I have an iframe (with designMode set to on) within a page that has a keypress listener in it. The keypress function listens for certain alt-character keystrokes, but I never want these alt-characters to actually show up in the iframe. How can I tweak my function so that these characters aren’t passed through to the iframe’s content?
function keyPress(e)
{
if(e.charCode == 402) //option f
{
//code to do stuff
//prevent character from passing through to content?
}
}
Use
event.altKeyto check whetheraltis pressed. Then, use thepreventDefault()method to prevent the default behaviour, andstopPropagation()to stop the event bubble.