onbeforeunload

Why is my onbeforeunload handler causing an “Unspecified error” error?

核能气质少年 提交于 2019-12-12 18:38:46
问题 I am using the following JavaScript function within IE6: window.onbeforeunload = function() { if (itemChanged) { return 'You have made changes to data on this page. If you navigate away from this page without first saving your data, the changes will be lost.'; } }; But when I press the Cancel button on the dialog, I am getting a JavaScript page error: Error: Unspecified error. Any ideas? 回答1: Check your value of (itemChanged). Is it possible something else causes the error? It works fine for

Why IE10 fires beforeunload event when clicking on anchor element with javascript href and how to prevent it

隐身守侯 提交于 2019-12-12 12:18:48
问题 In order to track when user leaves the page, we listen to beforeunload event. Everything works fine until user, that uses IE10 , clicks on empty link (anchor) with javascript in href parameter instead of url. For example: <a href="javascript:void(0)">Empty link with JS in href</a> This case makes IE10 sometimes fire beforeunload event. Chrome/IE11 work fine (0 beforeunload s), while IE10 fires it from time to time, especially if you click it fast. Here is JSFiddle to try it. Does anyone know

mailto link (in chrome) is triggering window.onbeforeunload - can i prevent this?

亡梦爱人 提交于 2019-12-12 09:34:08
问题 Possibly related to How to open mailto link in Chrome with Window.open without creating a new tab? Hi all. I have a form page where i've put a window.onbeforeunload confirm, to stop people navigating away and losing their changes by accident: window.onbeforeunload = function(){ if(changed) return "You have unsaved changes. Do you really want to leave this page without saving?"; }; where changed is a variable i set to true whenever the user makes any changes. That's all fine. However, i've

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

浪尽此生 提交于 2019-12-12 08:23:10
问题 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

Why is OnBeforeUnload firing twice with asp:LinkButton?

非 Y 不嫁゛ 提交于 2019-12-12 08:16:18
问题 I have the following Jquery function to notify the user with a prompt when they have unsaved changes (similar to how SO does it) and are trying to leave the current screen. <!-- in my aspx page --> <script type="text/javascript" language="javascript"> window.onbeforeunload = function() { if (HasPendingUpdates()) { return "Changes you have made will not be saved."; } } </script> This works as expected and shows the message box when the user tries to click a href to browse away or use the back

OnBeforeUnload to redirect user

匆匆过客 提交于 2019-12-12 04:08:23
问题 In my OnBeforeUnload event, it asked the user whether they want to leave the page or stay on it. When they click "stay on page", I want it to then redirect them to another webpage in the same window. Is there a way to do this, without just showing/hiding divs? Can I override the function? 回答1: Interesting! Possible in Internet Explorer: window.onbeforeunload = function() { window.onbeforeunload = null; location.assign('http://example.com'); return "Warning message"; }; Firefox will go to the

Opening another window in Javascript when user presses X on browser

喜你入骨 提交于 2019-12-11 18:54:51
问题 I understand this question has been asked and either answered or rejected before, but i promise i have a reasonably legit reason for asking. I am doing a Uni course and one of the requirements for the web app we are making is to have a certain page (daily sales report) open once the user presses X on the browser, this is a local file only ans aside from using window.onbeforeunload = window.open("dailyreport.html"); , which opens the page every time I do anything (click links etc) I have hit a

How to click on onbeforeunload prompt in Watir test?

南楼画角 提交于 2019-12-11 15:46:27
问题 I have a webpage that has an onbeforeunload script that prompts the user when they take an action that would navigate away from the current page. How do I interact with this popup using Watir? My current approach looks like this: $ie.link(:text, 'Dashboard').click_no_wait hwnd = $ie.enabled_popup(10) assert(hwnd, 'The expected \'leave this page?\' popup was not shown') win = WinClicker.new win.makeWindowActive(hwnd) win.clickWindowsButton_hwnd(hwnd, "OK") The problem is that if I use "click

AngularJS window.onbeforeunload is not working on Android and Iphone

心已入冬 提交于 2019-12-11 15:29:12
问题 I am using the following code:- .directive('confirmOnExitForm', function() { return { link: function($scope, elem, attrs) { window.onbeforeunload = function(){ if ($scope.form.$dirty) { return "The form is dirty, do you want to stay on the page?"; } } } }; }) This code is working fine on Desktops Chrome and Safari, but it is not working for Android and Iphones. Any idea why? 来源: https://stackoverflow.com/questions/47150350/angularjs-window-onbeforeunload-is-not-working-on-android-and-iphone

Which event handler to use to record leaving page - onunload or onbeforeunload?

一曲冷凌霜 提交于 2019-12-11 13:02:22
问题 Having not any answers to my previous questions about using javascript to measure page turn times, I'm going to start writing my own code (!). To measure the length of tie it takes, I'm proposing dropping a cookie containing a timestamp when the user browses away from a page, then in a subsequent page, comparing that time with 'now' and sending back a request to a URL which will log the interval. It seems that there are 2 possible handlers I could associate the first block of code with - the