我有一个奇怪的问题与jQuery(1.6.x)。我有我的网页上这个简单的调用:为什么jQuery有时会覆盖window.onbeforeunload?
window.onbeforeunload = function() { return 'Are you sure ?'; };
但它不工作,因为我已经找到了,jQuery的覆盖window.onbeforeunload的内容。在JS控制台,我可以看到window.onbeforeunload包含一段jQuery代码:
function(e) {
// Discard the second event of a jQuery.event.trigger() and
// when an event is called after a page has unloaded
return typeof jQuery !== "undefined" && (!e || jQuery.event.triggered !== e.type) ?
jQuery.event.handle.apply(eventHandle.elem, arguments) : undefined;
};
有没有一种方法,我可以找到原因和地点jQuery的覆盖我的onbeforeunload功能?当我尝试运行空jsfiddle时,只加载了jQuery并使用我的onbeforeunload函数,它按预期工作。
任何提示将不胜感激。提前致谢。
编辑:
以防万一,有人建议使用:
$(window).bind('beforeunload', function() { return 'Are you sure';});
我已经尝试过了,它的行为方式与使用纯JavaScript相同。
您可以使用jQuery'unload'方法吗? http://api.jquery.com/unload/ –
我能够成功地将自己的函数应用于'onbeforeunload',并使用jQuery 1.6。有没有更多的信息或代码可以提供?这不适用于所有浏览器吗? http://jsfiddle.net/Kai/QgVE8/ – Kai
你在太空中尖叫。提供重现此问题的测试案例,我们可以提供帮助。 – mekwall