Why jQuery sometimes overwrites window.onbeforeunload?

两盒软妹~` 提交于 2019-12-04 04:48:55

Ok, I've finally figured a solution, which is probably not the cleanest one - because I don't know the exact cause of the problem - but it works. I've put my beforeunload function into jQuery's load function so it is executed after DOM and other elements are loaded.

$(window).load(function () {
  $(window).bind('beforeunload', function() { return 'Are you sure ?';} );
});
robbywashere

You might have some luck trying a setTimeout(function(){ ... },0), I ran into the same problem and this worked as a viable solution.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!