onbeforeunload

Can I pop up a confirmation dialog when the user is closing the window in Safari/Chrome?

五迷三道 提交于 2019-11-26 09:59:38
问题 In IE and FF, i can attach an event handler to onBeforeUnload, and by passing a string to a property of the event, the user will see a dialog asking him whether he wants to continue with the \"unloading\" (either closing the window or navigating away). Safari and Chrome don\'t support onBeforeUnload, and onUnload seems to be too late. Is there some way to replicate the same functionality in Safari/Chrome? NOTE: I\'m not trying to keep the user hostage. I know this is nagging and un-cool. In

$(window).unload is not firing

流过昼夜 提交于 2019-11-26 09:58:36
问题 I want to execute an action method when the user is abandoning a particular page using jQuery. The page has the following code: <script type=\"text/javascript\"> $(window).unload(function () { alert(\"Handler for .unload() was called.\"); }); </script> When I navigate away from the page I never see the expected alert. 回答1: Actually some browsers such as Google Chrome might block if you attempt to alert in a window unload . As a user I like this feature. Alerting everytime you try to navigate

Difference between onbeforeunload and onunload

a 夏天 提交于 2019-11-26 09:39:10
问题 What are the differences between onbeforeunload and onunload ? Also I have a specific question related to it\'s use on the iPad...I have a page (myPage.html) where I am trying to show an alert when the page is closed (i.e. X is pressed to close the tab on iPad) Now I tried using both window.onunload and window.onbeforeunload Below are my findings on the iPad; Using window.onunload , I am able to get an alert when user navigates to a different page from myPage.html (either by clicking on some

How to disable a “Reload site? Changes you made may not be saved” popup for (python) selenium tests in chrome?

谁说胖子不能爱 提交于 2019-11-26 08:35:31
问题 I am running automated (python) selenium tests on a chrome browser, and sometimes when a page is reloaded a popup appears on the screeen: Is it possible to configure the chrome selenium browser in such a way, that this popup does not appear ? If so, how to do that? Or are there other ways to supress this popup? Or to accept it? 回答1: This popup with text as Reload site? Changes you made may not be saved is the implementation of onbeforeunload property of WindowEventHandlers onbeforeunload The

Is there any way to use window.onbeforeunload on Mobile Safari for iOS devices?

允我心安 提交于 2019-11-26 08:14:23
问题 Looks like Apple has disabled the window.onbeforeunload event for iOS devices (iPhone, iPad, iPod Touch). Unfortunately I can\'t find any documentation as to why this event doesn\'t work in Mobile Safari. Does anyone know if there\'s a reliable alternative to this function? Android\'s browser appears to support it just fine, and the Safari desktop application also supports the onbeforeunload event without issue. 回答1: I see that it's an old question, but i faced this problem recently. I'm

How to prevent closing browser window?

烂漫一生 提交于 2019-11-26 07:55:15
I tried the following code to get an alert upon closing a browser window: window.onbeforeunload = confirmExit; function confirmExit() { return "You have attempted to leave this page. If you have made any changes to the fields without clicking the Save button, your changes will be lost. Are you sure you want to exit this page?"; } It works, but if the page contains one hyperlink, clicking on that hyperlink raises the same alert. I need to show the alert only when I close the browser window and not upon clicking hyperlinks. M. Utku ALTINKAYA Keep your code as is and use jQuery to handle links: $

jQuery UI Dialog OnBeforeUnload

假如想象 提交于 2019-11-26 06:00:35
问题 I have a small problem. I\'m attempting to catch the OnUnLoad Event of the Window and ask a confirmation question and if the user decides they want to stay then fine, and if they want to leave the page then they\'ll lose all unsaved data. Here\'s the issues... I\'m using a jQuery UI Dialog and when I put the following code on my page, I have the Dialog open, and when I click the back button on the browser, it never pops up the msgbox. It just refreshes the page: <script type=\"text/javascript

Way to know if user clicked Cancel on a Javascript onbeforeunload Dialog?

瘦欲@ 提交于 2019-11-26 04:21:56
问题 I am popping up a dialog box when someone tries to navigate away from a particular page without having saved their work. I use Javascript\'s onbeforeunload event, works great. Now I want to run some Javascript code when the user clicks \"Cancel\" on the dialog that comes up (saying they don\'t want to navigate away from the page). Is this possible? I\'m using jQuery as well, so is there maybe an event like beforeunloadcancel I can bind to? UPDATE : The idea is to actually save and direct

How to show the “Are you sure you want to navigate away from this page?” when changes committed?

﹥>﹥吖頭↗ 提交于 2019-11-26 03:13:14
问题 Here in stackoverflow, if you started to make changes then you attempt to navigate away from the page, a javascript confirm button shows up and asks: \"Are you sure you want to navigate away from this page?\" blee blah bloo... Has anyone implemented this before, how do I track that changes were committed? I believe I could do this myself, I am trying to learn the good practices from you the experts. I tried the following but still doesn\'t work: <html> <body> <p>Close the page to trigger the

window.onbeforeunload not working on the iPad?

a 夏天 提交于 2019-11-26 03:09:00
问题 Does anyone know if the onbeforeunload event is supported on the iPad and/or if there\'s a different way to use it? I\'ve tried pretty much everything, and it seems like the onbeforeunload event is never triggered on the iPad (Safari browser). Specifically, this is what I\'ve tried: window.onbeforeunload = function(event) { event.returnValue = \'test\'; } window.onbeforeunload = function(event) { return \'test\'; } (both of the above together) window.onbeforeunload = function(event) { alert(\