Skip to content Skip to sidebar Skip to footer

How Can I Rewrite Onkeydown On The Html Element?

I inherited an application that implements disabling F5 in a window popup. However if the user clicks below the body in the window and presse

Solution 1:

$('html').bind('keydown', function(){ disableF5(); });

See the documentation for $.bind()

Edit – Moderately verbose explanation:

HTML onstuff attributes are evaluated as the DOM is loaded. Adding them post-factum doesn't have any effect. Thus, proper JS event binding must be used.

Solution 2:

This works in latest Chrome and FireFox and seems cleaner than bind to me:

$(document.documentElement).keydown(disableF5);

Solution 3:

$('html').bind('keydown', function() { disableF5(); }));

Post a Comment for "How Can I Rewrite Onkeydown On The Html Element?"