I find out that location.reload() call doesn’t do anything when I called to it from keyDown event handler when ESC button is pressed. Does anybody knows some workaround how to reload the page? Also I find http://bugs.jqueryui.com/ticket/4922 and it looks like this problem is already fixed.
Here is a sample of code.
subscription to event:
jQuery(document).keydown(function (event) {
if (event.keyCode == 27) {
closeVideoPopup();
}
});
And closeVideoPopup() method:
function closeVideoPopup() {
jQuery('#fade, .window_container').fadeOut(function(){
jQuery('#fade, a.close').remove();
});
jQuery('ul.tabs').css('z-index', '99');
jQuery('div.framing_slider').css('z-index', '9999');
location.reload();
return false;
}
Please note this code works perfect in all browsers except FF.
That’s because the Esc key stops the refresh immediately after you fire it in Firefox.
Use a
setTimeoutso thelocation.reload()will execute after the event has already finished bubbling.Fiddle
Or better, just call
event.preventDefault()so the Esc key won’t cancel the page reload:Fiddle