|
|
 |
 |
 |
 |
Javascript / Client Side Development
|
 |
 |
 |
 |
 |
 |
 |
 |
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, Ciarn
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/
On May 21, 6:11 pm, Randy Webb <HikksNotAtH@aol.com> wrote: > 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.
Ciaran said the following on 5/21/2007 3:18 PM: > On May 21, 6:11 pm, Randy Webb <HikksNotAtH @aol.com> wrote: >> 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/
On May 21, 5:43 pm, Ciaran <cronok@hotmail.com> wrote: > 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, > Ciarn
Anyone?
On May 21, 10:43 am, Ciaran <cronok@hotmail.com> wrote: > 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
On May 23, 11:35 pm, "scripts.contact" <scripts.cont@gmail.com> wrote:
> On May 21, 10:43 am, Ciaran <cronok @hotmail.com> wrote: > > 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';
}
On May 23, 5:33 pm, Ciaran <cronok@hotmail.com> wrote: > > 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
On May 24, 12:52 am, "scripts.contact" <scripts.cont@gmail.com> wrote:
> On May 23, 5:33 pm, Ciaran <cronok @hotmail.com> wrote: > > > 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! Ciarn
|
 |
 |
 |
 |
|