onbeforeunload

onBeforeUnload not working correctly for Chrome

烈酒焚心 提交于 2019-11-29 01:49:41
I've been using this code for some time and it worked fine until yesterday: window.onbeforeunload = function() { return "¡Atención! Si continúas no podrás volver atrás y podrías perder datos. Revisa todos los campos y termina el trabajo antes de moverte de esta página. ¿Seguro que quieres continuar?"; } The problem now is that Chrome shows this: But Edge shows it the right way: What am I doing wrong? Note: Language is not the problem because I've tried with both English and Spanish. You're not doing anything wrong. Google has decided to do what Mozilla did and not allow you to show a custom

Using onbeforeunload without dialog?

断了今生、忘了曾经 提交于 2019-11-29 01:18:37
I'm trying to post data when a user leaves my page. I have finally managed to find a working solution, however, it shows a confirmation dialog when the user leaves. I have tried return null; but it didn't work. Is it possible to disable the dialog? window.onbeforeunload = function() { $.post("track.php", { async: false, refid: refid, country: country, type: type, }); return ''; } From the Mozilla Developer Network page : When this event returns a non-void value, the user is prompted to confirm the page unload. This means the return value of the handler must be undefined (not '' , false , or

Is there any way to make onbeforeunload work in Opera?

家住魔仙堡 提交于 2019-11-28 14:38:40
I know, that Opera doesnt support JS onbeforeunload message and will not support it. But is there any way to make it work somehow? Or maybe some jQuery plugins can make it work and let script know if window is going to close? I found only way to make onclick for every a tag, but this is not the complete solution. Upgrade to Opera 15. onbeforeunload is now supported in that version because they moved to the WebKit engine. It is still not supported in 12.x because that version and all prior versions are based on Presto. Brian It is not possible to use onbeforeunload with Opera. There is a cross

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

白昼怎懂夜的黑 提交于 2019-11-28 13:50:17
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? This popup with text as Reload site? Changes you made may not be saved is the implementation of onbeforeunload property of WindowEventHandlers onbeforeunload The onbeforeunload property of the WindowEventHandlers mixin is the EventHandler for processing beforeunload

catching beforeunload confirmation canceled?

点点圈 提交于 2019-11-28 12:29:16
问题 I want to do some stuff when user is leaving a page, I add this code window.onbeforunload = function (e){ return "You save some unsaved data, Do you want to leave?"; } This prompt can notify the user and user can stay on the page or leave. But I want more to know whether he leaves or not, and do thing on his decision. I tried this, window.onbeforunload = function (e){ var event = jQuery.Event(e); var result = confirm('want to leave?'); if (result == false){ //do sth.. event.preventDefault();

How to send an HTTP request onbeforeunload in AngularJS?

笑着哭i 提交于 2019-11-28 12:08:24
I have a simple angular app that has two views that are loaded using ngRoute. I need to do some clean up on the server when the user navigates between views and when the user leaves the page (refreshes window, closes tab, or closes browser). My first stop was here: Showing alert in angularjs when user leaves a page . It solved the first case where the user navigates between views. I've handled the clean up like this: $scope.$on('$locationChangeStart', function (event) { var answer = confirm("Are you sure you want to leave this page?") if (answer) { api.unlock($scope.id); //api is a service

Why is jQuery onbeforeunload not working in Chrome and Firefox? [duplicate]

房东的猫 提交于 2019-11-28 12:01:43
This question already has an answer here: Crossbrowser onbeforeunload? 5 answers jQuery onbeforeunload is not working in Chrome and Firefox. It works properly in IE and Safari. jQuery(window).bind('onbeforeunload' ,function () { mymethod(); }); Above code works properly in IE and in Safari but not in Firefox and Chrome. According to MDN's window.onbeforeunload reference, The function should assign a string value to the returnValue property of the Event object and return the same string. Observe this jsFiddle jQuery(window).bind('beforeunload', function(e) { var message = "Why are you leaving?"

How to make a cross-browser on-window-unload request?

我与影子孤独终老i 提交于 2019-11-28 10:24:31
I have a Flash game that I'm trying to save the state of when the user closes the browser tab. It is using the following jquery code: //Called from Flash when window closes function sendRequest(url, params) { $.ajax({ type: "POST", async: false, url: url, data: params }) } $(window).unload(function() { //Make Flash attempt to save the game when the window closes. //Flash gets the necessary data and calls sendRequest() document["flashGame"].saveBeforeUnload(); }); Firefox: Works correctly Chrome: Works correctly when reloading but not when closing tabs or closing the browser IE (all versions):

Onbeforeunload doesn't work until mouse is clicked once in the body

送分小仙女□ 提交于 2019-11-28 10:12:31
问题 After a long day of trying to find a solution to this problem, I keep getting the same issue. Basically, I have a site, if the user clicks on the "browser-refresh" button, I want to pop-up a "are you sure" alert box with the options "reload" and "don't reload" (Basically, what the browser returns). Surprisingly, it works just fine in IE. But in chrome or firefox, the refresh happens normally without a popup. The popup only appears if I click on the body some where and then click on the

Detecting whether user stayed after prompting onBeforeUnload

巧了我就是萌 提交于 2019-11-28 10:06:24
In a web app I'm working on, I'm capturing onBeforeUnload to ask the user whether he really wants to exit. Now, if he decides to stay, there are a number of things I'd like to do. What I'm trying to figure out is that he actually chose to stay. I can of course declare a SetTimeout for "x" seconds, and if that fires, then it would mean the user is still there (because we didn't get unloaded). The problem is that the user can take any time to decide whether to stay or not... I was first hoping that while the dialog was showing, SetTimeout calls would not fire, so I could set a timeout for a