onbeforeunload

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

故事扮演 提交于 2019-12-02 13:18:35
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."; } } This looks like by design, as WindowEventHandlers.onbeforeunload - Web APIs | MDN has this note: To combat unwanted pop-ups

Why the OnBeforeUnload doesn't intercept the back button in my GWT app?

时光总嘲笑我的痴心妄想 提交于 2019-12-02 11:35:47
问题 I have a hook on the beforeUnload event. If i try to click on a link, reload or close the tab or the navigator, the app ask for confirmation before leaving. That's the desired behavior. But if click on the back button or the backspace outside an input, no confirmation. At the beginning of the html : window.onbeforeunload = function() { if (confirmEnabled) return ""; } And i use the Gwt PlaceHistoryMapper. What did i miss ? Where did i forgot to look ? Thanks ! 回答1: As long as you stay within

Fire onbeforeunload confirm alert for external sites only

爷,独闯天下 提交于 2019-12-02 06:50:20
问题 I am using window.onbeforeunload method to show confirm message if user leaves website. window.onbeforeunload = function(e) { return textMsg; }; But I need this to be fired only if user navigates to external web-site or closes window. So how to cancel this confirm message for all XHR inside same domain and form submit etc? 回答1: Try (untested code): window.onbeforeunload = function(e) { return textMsg; }; $('a:not([href^="http"])').on('click', function() { window.onbeforeunload = null; //

check if changes saved before unload

我的未来我决定 提交于 2019-12-02 06:07:36
问题 I have the following javaScript EDIT: included assignments for cahngesSaved var changesSaved = true; $(document).ready(function () { $(".applyChanges").click(function (e) { e.preventDefault(); var id = (this).id; var dayofweek = document.getElementById("dayofweek" + id).value; var hour = document.getElementById("hour" + id).value; var duration = document.getElementById("duration" + id).value; $.ajax({ url: '@Url.Action("ApplyChanges")', type: 'POST', data: { id: id, dayofweek: dayofweek, hour

Running a PHP through Ajax on Unload

我怕爱的太早我们不能终老 提交于 2019-12-02 05:20:31
问题 I'm trying to have a php script run when the user navigates away from the page. This is what I'm using currently: function unload(){ var ajaxRequest; // The variable that makes Ajax possible! try{ // Opera 8.0+, Firefox, Safari ajaxRequest = new XMLHttpRequest(); } catch (e){ // Internet Explorer Browsers try{ ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try{ ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ // Something went wrong window.location =

Why the OnBeforeUnload doesn't intercept the back button in my GWT app?

☆樱花仙子☆ 提交于 2019-12-02 04:25:27
I have a hook on the beforeUnload event. If i try to click on a link, reload or close the tab or the navigator, the app ask for confirmation before leaving. That's the desired behavior. But if click on the back button or the backspace outside an input, no confirmation. At the beginning of the html : window.onbeforeunload = function() { if (confirmEnabled) return ""; } And i use the Gwt PlaceHistoryMapper. What did i miss ? Where did i forgot to look ? Thanks ! As long as you stay within your app, because it's a single-page app , it doesn't by definition unload , so there's no beforeunload

check if changes saved before unload

▼魔方 西西 提交于 2019-12-01 23:25:40
I have the following javaScript EDIT: included assignments for cahngesSaved var changesSaved = true; $(document).ready(function () { $(".applyChanges").click(function (e) { e.preventDefault(); var id = (this).id; var dayofweek = document.getElementById("dayofweek" + id).value; var hour = document.getElementById("hour" + id).value; var duration = document.getElementById("duration" + id).value; $.ajax({ url: '@Url.Action("ApplyChanges")', type: 'POST', data: { id: id, dayofweek: dayofweek, hour: hour, duration: duration }, success: function (data) { $('#Calendar').fullCalendar('refetchEvents') $

获取页面离开onbeforeunload与onunload事件的返回值

断了今生、忘了曾经 提交于 2019-12-01 21:55:32
在各种项目开发的过程中,页面离开事件onbeforeunload是我们经常要用到的,可以避免用户操作失误,给用户一个选择的机会,就比如我们常常用到的编辑器中。如果用户选择了离开,那么onunload或者onbeforeunload事件自然会触发;但若用户选择了取消,又该如何检测呢? 我们假定一个页面离开取消事件,叫做onunloadcancel。显然,这个事件应触发在用户按下对话框的取消按钮之后。但关闭提示对话框的触发流程并不是那么简单。我们先来回顾下这个过程: window.onbeforeunload = function(){ return "真的离开?"; } 当用户准备离开页面(比如按下关闭按钮,或者刷新页面等等),onbeforeunload事件触发。我们的脚本无法在这个事件里决定是否阻止页面的关闭,唯一能做到的只有返回一个字符串,这个字符串仅作为说明文字出现在关闭选择对话框里,用户可以选择关闭,或者不关闭。但究竟选择哪个,我们无从得知。 然而仔细分析下这个问题,其实不然。 如果用户真选择了关闭页面,那么之后所有的运行代码都byebye了;而继续留在页面的话,就当什么都没发生过,除了onbeforeunload事件。所以,我们在onbeforeunload事件里做点小花招,在此注册个几毫秒之后启动的定时器,如果页面真关闭了,那么这个定时器当然是作废了;那么页面还在

获取页面离开onbeforeunload与onunload事件的返回值

霸气de小男生 提交于 2019-12-01 18:50:50
在各种项目开发的过程中,页面离开事件onbeforeunload是我们经常要用到的,可以避免用户操作失误,给用户一个选择的机会,就比如我们常常用到的编辑器中。如果用户选择了离开,那么onunload或者onbeforeunload事件自然会触发;但若用户选择了取消,又该如何检测呢? 我们假定一个页面离开取消事件,叫做onunloadcancel。显然,这个事件应触发在用户按下对话框的取消按钮之后。但关闭提示对话框的触发流程并不是那么简单。我们先来回顾下这个过程: window.onbeforeunload = function(){ return "真的离开?"; } 当用户准备离开页面(比如按下关闭按钮,或者刷新页面等等),onbeforeunload事件触发。我们的脚本无法在这个事件里决定是否阻止页面的关闭,唯一能做到的只有返回一个字符串,这个字符串仅作为说明文字出现在关闭选择对话框里,用户可以选择关闭,或者不关闭。但究竟选择哪个,我们无从得知。 然而仔细分析下这个问题,其实不然。 如果用户真选择了关闭页面,那么之后所有的运行代码都byebye了;而继续留在页面的话,就当什么都没发生过,除了onbeforeunload事件。所以,我们在onbeforeunload事件里做点小花招,在此注册个几毫秒之后启动的定时器,如果页面真关闭了,那么这个定时器当然是作废了;那么页面还在

获取页面离开onbeforeunload与onunload事件的返回值

房东的猫 提交于 2019-12-01 18:41:35
在各种项目开发的过程中,页面离开事件onbeforeunload是我们经常要用到的,可以避免用户操作失误,给用户一个选择的机会,就比如我们常常用到的编辑器中。如果用户选择了离开,那么onunload或者onbeforeunload事件自然会触发;但若用户选择了取消,又该如何检测呢? 我们假定一个页面离开取消事件,叫做onunloadcancel。显然,这个事件应触发在用户按下对话框的取消按钮之后。但关闭提示对话框的触发流程并不是那么简单。我们先来回顾下这个过程: window.onbeforeunload = function(){ return "真的离开?"; } 当用户准备离开页面(比如按下关闭按钮,或者刷新页面等等),onbeforeunload事件触发。我们的脚本无法在这个事件里决定是否阻止页面的关闭,唯一能做到的只有返回一个字符串,这个字符串仅作为说明文字出现在关闭选择对话框里,用户可以选择关闭,或者不关闭。但究竟选择哪个,我们无从得知。 然而仔细分析下这个问题,其实不然。 如果用户真选择了关闭页面,那么之后所有的运行代码都byebye了;而继续留在页面的话,就当什么都没发生过,除了onbeforeunload事件。所以,我们在onbeforeunload事件里做点小花招,在此注册个几毫秒之后启动的定时器,如果页面真关闭了,那么这个定时器当然是作废了;那么页面还在