atar.yosef Posted October 29, 2012 Share Posted October 29, 2012 Hi there!!I don't know why, but when I am loading the following code snippet in my iPod touch browser, so when I hit the "Backspace" key, the function is called twice instead of being invoked once. Can someone help me know why does this occur?Thanks in advance!!Atar. <html><head><title></title><script type="text/javascript">try{function myFunction(e){if(e.keyCode==8){alert("The Backspace button has been pressed");}//end if.}//end myFunction().}//end try statement.catch(err){alert("there's an error in this page. \n the error message is:\n" + err.message + "\n the error name is: \n" + err.name + "\n and the error details are:\n" + err.constructor + "\n and the error stack is: \n" + err.stack);}//end catch statement.</script><style type="text/CSS"></style></head><body><input type="text" onkeydown="myFunction(event)" value="something"></input></body></html> Link to comment Share on other sites More sharing options...
thescientist Posted October 29, 2012 Share Posted October 29, 2012 maybes it's somehow getting called twice. could be some sort of behavior quirk with key events in iOS. Link to comment Share on other sites More sharing options...
ReGA Posted November 10, 2012 Share Posted November 10, 2012 (edited) Yes, the event onkeydown gets called repeatedly if you hold a key.I had a similar problem in firefox. But this only happens after a certain delay. You can avoid this by using an onkeyup event: <html><head><script>var hasPressed=false;function myFunction(e,keyDown) { if (hasPressed && keyDown) return; hasPressed=keyDown; // Code}</script></head><body><input type="text" onkeydown="myFunction(event,true)" onkeyup="myFunction(event,false)"></body></html> Edited November 10, 2012 by ReGA Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now