Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I create hotkeys? 2

Status
Not open for further replies.

Scanlan

Technical User
Sep 7, 2001
35
0
0
US
Hello all.

I have a little Internet application (ASP pages, SQL database, that sort of thing). After a user logs in, they are taken to a welcome page from which they can do any number of things by clicking on links for different ASP pages.

I got a user request recently and I have no idea if it would be possible. Is there a way to make hotkeys on a web page? (For instance, pressing F1 opens Page A, F2 opens Page B, F3 opens Page C.)

It doesn't have to be JavaScript, I am cross-posting this in the hopes of getting either a definitive not possible or some ideas on how to approach this issue. Since my application is in limited usage, I can say that I only have to support IE.

Thanks in advance for your help.
Ann
 
It could be done easily with javascript but I'm not sure about using the 'F' keys. If you wanted to do it with keys from the number pad or any other keys (with the exception of the 'F' keys) it would be easy. Let me know if you want to do it without the 'F' keys and I'll post some code to get you started.
 
Yes, I can definitely do it with just regular keys. I would appreciate some help getting started.

Thanks,
Ann
 
Ok try this out and tell me if that's what you wanted. Also, I left in some stuff so you could better understand it and modify it.

This goes in the head of your page:

<Script Language=&quot;javascript&quot;>
<!--
document.onkeydown = keyDown;
ns4 = (document.layers)? true:false
ie4 = (document.all)? true:false
function keyDown(e)
{
if (ns4)
{
var nKey = e.which
document.frmBreak.text1.value = &quot;nKey=&quot; + nKey
}
if (ie4)
{
var ieKey = event.keyCode;
document.frmBreak.text1.value = &quot;ieKey=&quot; + ieKey;
}
switch (ieKey)
{
case ieKey = 71:
//alert('Google');
document.location = ' break;

case ieKey = 89:
//alert('Yahoo');
document.location = ' break;

default:
alert('Error');
}
}
//-->
</Script>


Put this in the body of the page (This is to help you get the value of the key pressed). You can take it out later when your ready to put the page into use.

<Form name=&quot;frmBreak&quot;>
<INPUT type=&quot;text&quot; id=text1 name=text1>
</Form>
 
If I could get this to work, I think this would be what I want. The key values show up really nice-- that was a good idea. I changed the values in your code to 49 and 50, but I just get error messages, no matter what key I press.

Not sure what the problem is. Also, could you please explain what this part of your code does (I can follow the rest ok, but I don't understand this bit)?

document.onkeydown = keyDown;
ns4 = (document.layers)? true:false
ie4 = (document.all)? true:false


Thanks,
Ann
 
This line gets the key that was pressed:

document.onkeydown = keyDown;


The first line is just saying if your browser is netscape then ns4 = true otherwise it's false. The second line is checking the brower to see if it is internet explorer. If it is ie4 = true otherwise it gets false.

ns4 = (document.layers)? true:false
ie4 = (document.all)? true:false

Also, take out this part of the code:(It will get rid of your errors)

default:
alert('Error');

Post your code so I can take a peak at it and I'll try to find your errors.
 
Excellent, thank you.

Taking out the lines you said not only got rid of the errors, it also made the code work. Pressing 1 takes me to google, 2 to yahoo.

This is exactly what I want. I will just adapt it for my application.

Thank you so much,
Ann
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top