window.onunload = alert("Are you sure 2?");
This is incorrect. You are setting onunload
to the result of alert
, you need to set it to a function:
window.onunload = function(){
alert("Are you sure?");
}
If you want to use jQuery, this will work in all browsers.
$(window).unload(function () {
alert("Are you sure?");
});
NOTE: It might seem like it's not working in Chrome, but it is. That's because Chrome blocks alert
s in the onunload
event.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…