onbeforeunload

window.onbeforeunload in Chrome: what is the most recent fix?

家住魔仙堡 提交于 2019-12-17 06:41:39
问题 Obviously, window.onbeforeunload has encountered its fair share of problems with Chrome as I've seen from all the problems I've encountered. What's the most recent work around? The only thing I've got even close to working is this: window.onbeforeunload = function () { return "alert" }; However, if I substitute return "alert" with something like alert("blah"), I get nothing from Chrome. I saw in this question that Google purposefully blocks this. Good for them... but what if I want to make an

window.onbeforeunload not working in chrome

亡梦爱人 提交于 2019-12-17 04:35:27
问题 This is the code which i used for window.onbeforeunload...... <head> <script> window.onbeforeunload = func; function func() { var request = new XMLHttpRequest(); request.open("POST", "exit.php", true); request.onreadystatechange = stateChanged; request.send(null); } function stateChanged() { if (request.readyState == 4 || request.readyState == "complete") alert("Succes!"); } </script> </head> this works with IE and mozila but does not work with chrome..... please help...... thanks in advance.

Setting onbeforeunload on body element in Chrome and IE using jQuery

喜欢而已 提交于 2019-12-17 04:08:47
问题 I have a system where I want to check with the user if they're sure they want to leave the page once a dirty flag is set. I'm using the following code - In FireFox, I can look at the page source through FireBug and the tag correctly has the onbeforeunload attribute inserted in it. In Chrome and FireFox, this doesn't happen though and I'm able to navigate away from the page without any warning at all. The jQuery line to update the body tag is definitely being executed, it just isn't performing

Setting onbeforeunload on body element in Chrome and IE using jQuery

蓝咒 提交于 2019-12-17 04:08:20
问题 I have a system where I want to check with the user if they're sure they want to leave the page once a dirty flag is set. I'm using the following code - In FireFox, I can look at the page source through FireBug and the tag correctly has the onbeforeunload attribute inserted in it. In Chrome and FireFox, this doesn't happen though and I'm able to navigate away from the page without any warning at all. The jQuery line to update the body tag is definitely being executed, it just isn't performing

Javascript, controlling an onbeforeunload tag

孤街浪徒 提交于 2019-12-14 03:57:08
问题 I'm trying to set up a onbeforeunload tag to stop a user from leaving specific pages if and only if they have unsaved content, and only on specific pages (we're using a single master page). I quickly discovered that having a return ##anything## in the onbeforeunload tag would always trigger a javascript confirm, and puts ##anything## inside the pop-up. Obviously, this is now expected behavior, but it does take away my idea of using my own confirm box that could be controlled with an if

Help required on onbeforeunload or click on browser back button

自作多情 提交于 2019-12-13 14:27:08
问题 If a user clicks the browser's back button, then I want a prompt to appear and ask for confirmation. If the user clicks 'OK', then it should navigate to xx.html . If the user clicks 'Cancel', then it should prevent the navigation. How can I do this? Note: Already I tried the onbeforeunload method, but it is working for all the navigation actions. For Example, clicking the link on the page will also fire this event and show the message to the user. 回答1: You can't. The best you can do is use

Return confirm in JavaScript

蓝咒 提交于 2019-12-13 07:37:22
问题 I have problem with return confirm in Chrome. In Firefox it is ok. window.onbeforeunload = function() { var result = confirm('Really?'); if(result) { console.log('Do something'); } } Any ideas? Thanks! 回答1: You should return something from beforeunload . The confirm will be ignored Since 25 May 2011, the HTML5 specification states that calls to window.showModalDialog(), window.alert(), window.confirm() and window.prompt() methods may be ignored during this event. see MDN window.onbeforeunload

Jquery Show Popup only when window is closed

烈酒焚心 提交于 2019-12-13 04:59:55
问题 I am trying to display a confirmation message when the user closes the browser/tab and not when any of the links on page is clicked. I have got the first part of displaying the message on window close working nicely but problem is that the message/alert is displayed also when user clicks on any link on the page. I have got code from somewhere to prevent this behavior but still when ever any link is clicked the alert pops up. Here is the code: <script src="js/jquery-1.7.1.min.js"></script>

Sending a request back to server in onbeforeunload event

懵懂的女人 提交于 2019-12-13 02:10:33
问题 When a user edits a record in my application I track that they have it 'locked' to prevent another user from editing it until the first user closed the window (or saves). I'm trying to send the request back to the server to unlock the record but it's not working in Firefox. The onbeforeunload event is called in script but it's not sending back the request to the server. Any ideas? <body> <script> window.onbeforeunload = function (e) { doUnlock(); } function doUnlock() { if (navigator.appName

window.onbeforeunload not firing in child window

我的未来我决定 提交于 2019-12-13 00:26:16
问题 I want to bind a function to the beforeunload event of a child window in Javascript. I have the following code: newWind = window.open(settings.url, "Dialog", "width=" + settings.width + ",height=" + settings.height + ",resizable=" + settings.resizable + ",scrollbars=" + true); newWind.onunload = function() { alert('test'); } Works fine in Firefox, but fails in IE7. Can anyone see what I am doing wrong? 回答1: newWind.onunload = function() { alert('test'); } IE won't let you assign a function