onbeforeunload

Why jQuery sometimes overwrites window.onbeforeunload?

两盒软妹~` 提交于 2019-12-04 04:48:55
I am having strange problem with jQuery (1.6.x). I have this simple call on my page: window.onbeforeunload = function() { return 'Are you sure ?'; }; But it doesn't work, because as I've found out, jQuery overwrites content of the window.onbeforeunload. In JS console, I can see that window.onbeforeunload contains piece of jQuery code: 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,

beforeunload on IE 11 - do not prompt user does not work

穿精又带淫゛_ 提交于 2019-12-04 00:38:58
When adding a listener to the global window object for the beforeunload event, IE 11 (and 10) does not behave as Chrome and Firefox. Normally, you return a string that will be used to populate the browser-native dialog prompt or you return an empty string if you do not want the dialog to prompt the user. However, in IE 11, if you return an empty string and/or set the evt.returnValue to an empty string, the browser-native 'Navigate Away' dialog is opened and prompts the user to acknowledge that they may lose unsaved changes. Is there any way (without having to remove the event listener) to have

prevent OnBeforeUnload() event from happening in refresh/F5

独自空忆成欢 提交于 2019-12-03 15:46:11
I'm using onbeforeunload event to perform operations during the closing page. I do not want the event to happen in the case of Refresh / F5 . Is there a way or other event to do this? zur4ik Unfortunately onbeforeunload event listens the page state in the browser. Going to another page as well as refreshing will change the page state, meaning onbeforeunload will be triggered anyway. So I think it is not possible to catch only refresh. But, if you'll listen and prevent Keypress via JavaScript, then it can be achieved. Refresh can be done via F5 and Ctrl R keys, so your goal will be to prevent

onbeforeunload event is too enthusiastic in IE9

耗尽温柔 提交于 2019-12-03 14:53:02
问题 Here's some sample test html: <!DOCTYPE html> <html> <body> <a href="javascript:alert('Not going anywhere!');">Go nowhere 1</a> <a href="javascript:void(0);" onclick="alert('Not going anywhere!');">Go nowhere 2</a> <a href="http://www.google.com">Go somewhere</a> <script type="text/javascript"> window.onbeforeunload = function() { return "Really leave?"; }; </script> </body> </html> This is available as a working page here: timjeanes.com/ie9_onbeforeunload.htm In Firefox, Chrome and Safari, I

window.onbeforeunload runs only when closing window not on refresh

耗尽温柔 提交于 2019-12-03 14:14:43
问题 I have this function window.onbeforeunload = function () { return "Are you sure?"; }; and I have a button that when the user presses it the window refreshes to update screen values and do some database calls. I added window.onbeforeunload=null; in the beginning of the function to disable onbeforeunload but it kept being called. Is there a way to either disable the onbeforeunload function in my button onclick function or make the window.onbeforeunload get called only on close window not on

Google chrome onbeforeunload wrong behavior with iframe

落花浮王杯 提交于 2019-12-03 11:06:16
Let say I have two pages. One of them contains another one inside as iframe. If you subscribe to onbeforeunload event on the parent page, then this event doesn't triggers if you close tab when iframe is in focus. I suppose it is a bug as written here: Google Chrome issues But I mentioned that, for example, google docs handle this situation. Can anyone give me a solution? Important note that I have no actual access to the iframe content as it is a third party html editor (WYSIWYG). Lucky Murari I know it is an old question but just to help people who are coming here through Search : The bug is

OnUnload Alert Error “NS_ERROR_NOT_AVAILABLE”

匿名 (未验证) 提交于 2019-12-03 02:30:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: <html> <body> <button type="button" onclick="clickme()">Click Me</button> <script> var test = 0; function clickme() { test = 1; console.log(test); } window.onunload = function() { alert("test"); } </script> </body> </html> I'm using this simple code to test some things with onunload and onbeforeunload. For some reason whenever I refresh/leave the page and cause the onunload event I get no alert and an error in the Firebug console. If I use onbeforeunload this works and I get no error, but I hear onbeforeunload isn't very good cross-browser.

window.onbeforeunload not working on Firefox 46 in a popup window, all other browsers work

大兔子大兔子 提交于 2019-12-02 22:10:11
问题 Having an issue with Firefox 46, on all the other browsers it work fine. Upon exit from the page I ask the following question. Firefox ignores it completely. Help please! window.onbeforeunload = ThisCheckExittingPage; var ThisCheckExitWindow = 1; // Checks before exitting // ThisCheckExitWindow = 1; // Does NOT check before exitting // ThisCheckExitWindow = 0; function ThisCheckExittingPage() { if (ThisCheckExitWindow == 1) { return "You are about to exit this page."; } } 回答1: This looks like

浏览器关闭,onunload和onbeforeunload的使用

匿名 (未验证) 提交于 2019-12-02 21:53:52
系统描述:用户与管理员客服聊天,当用户在五分钟之内不说话,则客服会在5分钟后断开。当直接关闭浏览器页面时,后台管理员就无法检测到这种状态,此用户无法从管理员的服务列表里面清除 onunload和onbeforeunload这两个事件可以在浏览器关闭或者刷新时调用 可以在<script>脚本中通过 window.onunload来调用。区别在于onbeforeunload在onunload之前执行,它还可 以阻止onunload的执行。 onbeforeunload (页面跳转时触发的事件。)是正要去服务器读 取新的页面时调用,此时还没开始读取;而onunload(浏览器卸载页面后执行的事件)则已经从服务器上读到了需要加载的新的页面,在即将替换掉当前页面时调用。 使用方法 // 监测关闭浏览器 var _beforeUnload_time = 0 var _gap_time = 0; var is_fireFox = navigator.userAgent.indexOf("Firefox") > -1; //是否是火狐浏览器 window.onunload = function() { _gap_time = new Date().getTime() - _beforeUnload_time; if (_gap_time <= 5) { //浏览器关闭 vm

How can I prevent window.onbeforeunload from being triggered by javascript: href links in IE?

落爺英雄遲暮 提交于 2019-12-02 14:41:43
I'm building a fail safe for my form that is going to warn users that if they leave the page their form data will be lost (similar to what gmail does). window.onbeforeunload = function () { if (formIsDirty) { return "You have unsaved data on this form. Don't leave!"; } } The above function works great in firefox, but in IE it is triggered by any href link, even ones that are links to javascript and not other pages. for example.... <a href='javascript:someFunction();'>click</a> I'm wondering if there is any way to get around this, as I do not want the user thinking that they are leaving the