I want to make my question clear. Please dont confuse it with determining the key press. I dont want the user to press any key. On the contrary, I want to run a script which fires the Escape key press event. Please help!
相关问题
- How to fix IE ClearType + jQuery opacity problem i
- jQuery add and remove delay
- Include empty value fields in jQuery .serialize()
- Disable Browser onUnload on certain links?
- how to get selected text from iframe with javascri
You can use
$.Event()
to create an Event object containing a keydown event with the keyCode of 27 (which should be Esc) like:See this working demo and the docs at jquery.com
Also note that, as stated by Christofer, this might not be working in all browsers and environments as it might be considered shady behavior that could be used in a malicious manner - just like triggering a click event on an
<a>
with an external href will not happen. I successfully tested this (the Esc) in Chrome, Safari, Opera, FF & IE9 though.For security reasons, some browsers (not sure if all), prevent you from firing keydown-events. Please refer to this article for more info.
A quote from the article: