我有一个beforeunload
功能:
jQuery(window).bind('beforeunload', function() {
if(inFormOrLink){
return inFormOrLink ? "Do you really want to close?" : null;
}});
此功能在Chrome中运行良好,但在Firefox中无效。对于Firefox,我使用此功能:
if(inFormOrLink){
var myEvent = window.attachEvent || window.addEventListener;
var chkevent = window.attachEvent ? 'onbeforeunload' : 'beforeunload';
myEvent(chkevent, function(e) {
var confirmationMessage = 'Are you sure to leave the page?'; // a space
(e || window.event).returnValue = confirmationMessage;
return confirmationMessage;
});
}
这很好用。当我得到inFormLink的值为false时,我的问题就像上面的函数一样有效。