Forum Moderators: open

Message Too Old, No Replies

how can I open a keypress link in a target window?

         

racmaster08

11:40 am on Sep 13, 2009 (gmt 0)

10+ Year Member



I want to open a keypress link in a target window, but I can't seem to work it out. Please help

whoisgregg

2:13 am on Sep 14, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld, racmaster08! :)

Could you post some code of what you've tried so far for us to take a look at?

Also, do you want the user to be able to type a key and have that open a new window? Or are you trying to accomplish something else?

racmaster08

11:05 am on Sep 14, 2009 (gmt 0)

10+ Year Member



<script language = "JavaScript">
document.onkeypress=function(e){
var e=window.event ¦¦ e

switch(e.keyCode){
case 97:
window.location.href = "demi.html";
break;
case 98:
window.location.href = "semi.html";
break;


}

here is the part of the code ive been trying...I want to open the following "demi.html" and "semi.html" inside a frame...but to do that...I need to specify the id of the frame...but i have no idea how, given that the code to open the link is window.location.href..

whoisgregg

7:35 pm on Sep 14, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There are a couple different approaches here. First, iframe's define the website using an src attribute, not an href attribute. So if you can access the iframe using an id and change the src like so:

document.getElementById('iframe_id').src='http://www.example.com/'

There's also a method for navigating through the DOM to identify an iframe with a name attribute. In this case you can use the same location.href approach:

self.frames['iframe_name'].location.href='http://www.example.com/'

Either one should do the trick, but cross browser testing is always recommended. :)

racmaster08

1:04 pm on Sep 16, 2009 (gmt 0)

10+ Year Member



ok thanks...i'll try both of them and see if there are some problems...

racmaster08

1:11 pm on Sep 16, 2009 (gmt 0)

10+ Year Member



it worked...that was a great help...thanks again...

whoisgregg

3:12 pm on Sep 16, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Glad I could help. :)