if you call preventDefault() on a keypress event for a particular keyCode, how long will the default be prevented? Is it for the life of a browser session or only while a particular page is loaded? IS the behaviour for stopPropagation() the same?
Some example code:
<script type="text/javascript">
<![CDATA[
function keydownhandler(e)
{
switch (e.keyCode)
{
case VK_BACK:
case 461:
preventDefault();
break;
default:
break;
}
}
document.addEventListener("keydown", keydownhandler, true);
]]>
</script>
preventDefault()prevents a default action to occur, i.e. the browser to post aformwhen enter is pressed. And this default action will be permanently prevented for this instance of the event. Next timeenteris pressed, you need to prevent that key press to.stopPropagation()stops the event from bubbling down to all elements above the element on which the event occured i.e:if you click the
<a>-tag the div till also get a bubbledclick-event on it.stopPropagation()will prevent this.EDIT: In your case every event with the
keyCode==VK_BACKor461will be prevented to make there default action.