473,320 Members | 1,902 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Cross browser key handler?

Hi has anyone got a function that can detect a user pressing a key
that works cross browser?
I just want to redirect my visitor if they hit escape ... you'd think
it would be easy!
Thanks,
Ciarán

May 21 '07 #1
8 5503
Ciaran said the following on 5/21/2007 12:43 PM:
Hi has anyone got a function that can detect a user pressing a key
that works cross browser?
I just want to redirect my visitor if they hit escape ... you'd think
it would be easy!
As easy as posting the same question 6 times?

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
May 21 '07 #2
On May 21, 6:11 pm, Randy Webb <HikksNotAtH...@aol.comwrote:
Ciaran said the following on 5/21/2007 12:43 PM:
Hi has anyone got a function that can detect a user pressing a key
that works cross browser?
I just want to redirect my visitor if they hit escape ... you'd think
it would be easy!

As easy as posting the same question 6 times?

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ -http://jibbering.com/faq/index.html
Javascript Best Practices -http://www.JavascriptToolbox.com/bestpractices/

Very funny. That was a server error.

May 21 '07 #3
Ciaran said the following on 5/21/2007 3:18 PM:
On May 21, 6:11 pm, Randy Webb <HikksNotAtH...@aol.comwrote:
>Ciaran said the following on 5/21/2007 12:43 PM:
>>Hi has anyone got a function that can detect a user pressing a key
that works cross browser?
I just want to redirect my visitor if they hit escape ... you'd think
it would be easy!
As easy as posting the same question 6 times?
Very funny. That was a server error.
The server caused you to click the Post button 6 times? That is one
powerful server you have there.

On further inspection, you are posting using Google Groups and I doubt -
very seriously - that the GG server has the ability to cause you to
click a button 6 times. But, nice try.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
May 21 '07 #4
On May 21, 5:43 pm, Ciaran <cronok...@hotmail.comwrote:
Hi has anyone got a function that can detect a user pressing a key
that works cross browser?
I just want to redirect my visitor if they hit escape ... you'd think
it would be easy!
Thanks,
Ciarán
Anyone?

May 23 '07 #5
On May 21, 10:43 am, Ciaran <cronok...@hotmail.comwrote:
Hi has anyone got a function that can detect a user pressing a key
that works cross browser?
I just want to redirect my visitor if they hit escape
try:

document.body.onkeypress=
function(e){
if((e||event).keyCode==27)
location.href="http://google.com";
}

untested

May 23 '07 #6
On May 23, 11:35 pm, "scripts.contact" <scripts.cont...@gmail.com>
wrote:
On May 21, 10:43 am, Ciaran <cronok...@hotmail.comwrote:
Hi has anyone got a function that can detect a user pressing a key
that works cross browser?
I just want to redirect my visitor if they hit escape

try:

document.body.onkeypress=
function(e){
if((e||event).keyCode==27)
location.href="http://google.com";

}

untested

Thanks for the reply! .... but it doesnt seem to be working. I have
this function working in IE but FF is ignoring it ...

if (document.layers) { document.captureEvents(Event.KEYPRESS); }
document.onkeypress = getKey;
function getKey(keyStroke) {
var keyCode = (document.layers) ? keyStroke.which : event.keyCode;
if(keyCode==27) location.href='quit.html';
}

May 23 '07 #7
On May 23, 5:33 pm, Ciaran <cronok...@hotmail.comwrote:
document.body.onkeypress=
function(e){
if((e||event).keyCode==27)
location.href="http://google.com";
}

Thanks for the reply! .... but it doesnt seem to be working. I have
this function working in IE but FF is ignoring it ...
Try this:

document.onkeypress=changeHREF
function changeHREF(ev){
ev=ev||event;
if(ev.keyCode==27){
location.href="http://google.com"
return false
}
}

works in o9,f2,i6

May 23 '07 #8
On May 24, 12:52 am, "scripts.contact" <scripts.cont...@gmail.com>
wrote:
On May 23, 5:33 pm, Ciaran <cronok...@hotmail.comwrote:
document.body.onkeypress=
function(e){
if((e||event).keyCode==27)
location.href="http://google.com";
}
Thanks for the reply! .... but it doesnt seem to be working. I have
this function working in IE but FF is ignoring it ...

Try this:

document.onkeypress=changeHREF
function changeHREF(ev){
ev=ev||event;
if(ev.keyCode==27){
location.href="http://google.com"
return false
}
}

works in o9,f2,i6
Wow! perfect! and such an elegant solution! I searched the net for a
key handler like this and everything I found was either 2 pages long
or only worked in ie. Thanks a lot!
Ciarán

May 24 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Joseph Barron | last post by:
Here is a SIMPLE problem that I'm trying to solve. It works in Netscape 6.2, but IE6 gives ""No such interface supported." Below are page1.htm and page2.htm . In page1.htm, there are two...
16
by: Java script Dude | last post by:
To all Mozilla JS Guru's (IE dudes welcome), I have spent the last three years developing complex DHTML applications that must work in IE 5.5sp2+ but I use Mozilla 1.3+** to do all my...
1
by: cjl | last post by:
Hey all: I'm trying to write a cross-browser (IE and firefox) event handler for the mousewheel. Basically my web app is an image viewer, so if you scroll "down" with the wheel the next image...
17
by: Mark Rae | last post by:
Hi, I'm interested in your opinion concerning how far you would consider it necessary to code for cross-browser compatibility these days, especially for public-facing Internet sites... ...
15
by: CMM | last post by:
So I'm half way through overseeing a large project in ASP.NET 2.0. My superiors have decided that it would be nice if we ensured the site worked on all the major platforms (as they see it: IE,...
2
by: mattgarvin | last post by:
Hello, I need a piece of javascript that will allow a form to be submitted when Enter is pressed for IE6 and 7, Firefox 2, and recent versions of Safari. It is for a login page that has two...
1
by: Ciaran | last post by:
Hi Does anyone have a simple function that captures a keystroke that works cross browser? I just want to redirect a page when a user hits esc... you'd think it would be easy! Cheers, Ciarán
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shćllîpôpď 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.