onbeforeunload

Showing a jQuery popup before browser window closes

淺唱寂寞╮ 提交于 2019-12-24 10:53:26
问题 I'm using the following js to show a popup before the browser/window closes. But it does not seem to be working. $(window).bind('beforeunload', function(e) { $('#beforeclose').click(); }); The popup i'm trying to show is prettyPopin . And the #beforeclose is the id of the anchor with which i'm trying to bind the click event before the window unloads. I have noticed that native js popups work but the jQuery popup does not work. Is there a way to achieve what i want to? Please do explain to me

How to show a modal dialog before beforeunload shows its own?

拜拜、爱过 提交于 2019-12-24 04:43:06
问题 I do understand that it's not possible to replace the beforeunload dialog with a custom one, and that if we need to set a custom message to the user, we'll have to return a string in our beforeunload handler: {Custom message here set by returning a string in our beforeunload handler} Are you sure you want to leave this page? [Leave this page] [Stay on this page] So, how about showing a custom modal dialog (maybe jQuery) before the actual beforeunload dialog is shown by the browser? My current

jQuery unload with an AJAX call not working in Chrome

旧街凉风 提交于 2019-12-24 04:29:26
问题 This is my very simple code snippet: $(window).unload(function() { $.ajax({ url: 'stats_pages.php?last_id='+$("#last_id").val(), }); }); Simple enough. The AJAX call gets called perfectly in Firefox, but fails in Chrome. I've tried other variations, which sort of work: window.onbeforeunload = function(){ $.ajax({ url: 'stats_pages.php?last_id='+$("#last_id").val(), }); return false; } This works in Chrome, but it alerts "false" with the usual "Are you sure you want to leave this page?"

Unable to set background-image property in “beforeunload” event

此生再无相见时 提交于 2019-12-23 22:36:39
问题 I'm trying to solve IE-problem of not animating a .gif image, when it is displayed in beforeunload or unload events. I step into this answer, but found it not working, so I played a little bit with this code. I have come with something like that: var spinner = $('.spinner-large'), spinnerBackgroundImage = spinner.css('background-image'); console.log(spinnerBackgroundImage); console.log($('.spinner-large').css('background-image')); spinner.css('background-image', spinnerBackgroundImage);

Display a warning with 'onbeforeunload' when leaving a page, except if 'Submit' is clicked

假装没事ソ 提交于 2019-12-23 09:27:47
问题 I wish to display a warning if a user attepmts to leave a page that contains unsaved settings, but obviously not if they are attempting to save those settings. I guess my understanding is wrong, as I thought the below should work, but it does not. Can somebody tell me what I am doing wrong? Thanks. $('input[name="Submit"]').off('onbeforeunload'); window.onbeforeunload = function closeEditorWarning(){ /** Check to see if the settings warning is displayed */ if($('#unsaved-settings').css(

Reliability of onbeforeunload

笑着哭i 提交于 2019-12-23 07:04:57
问题 How reliable is the event window.onbeforeunload ? Does it fire in all major browsers? Does it fire if the client browser crashes? (I believe in wonders) Is it able to delay the close event in case it might need "a little longer" or will it get cut off? Are there any alternatives? 回答1: Yes, onbeforeunload works in every browser I have ever tried it on. No, if a browser crashes then it dies, there is no way around that fact. I said "no" in my comment, but it does depend somewhat. For instance,

How to make the “onbeforeunload” function be disabled for my own pages and work only for external ones?

我们两清 提交于 2019-12-23 04:28:06
问题 How to make the onbeforeunload function be disabled for my own pages and work only for external ones? How to make disable the code that OG Sean gave here: "Are you sure you want to leave this page?" functions for cancel and OK <script> window.onbeforeunload = function(e) { return 'Are you sure you want to leave this page? You will lose any unsaved data.'; }; </script> for all my subpages like (domain.com/shop; domain.com/about-us; and domain.com/contact), and enable it only for when you click

user-unfriendly onbeforeunload / onunload

这一生的挚爱 提交于 2019-12-23 02:52:54
问题 I'm struggling with onbeforeunload, onunload and generating the right messages at the right time. Any idea welcome. This is the situation: when I use onbeforeunload, the user gets a message to choose whether to navigate away, but I can't turn it off - the message is standard and appears regardless what's in the event handler. when I use onunload, I can control the "bye" messages that occur, but I cant offer the user the opportunity to change their mind. So for example, if there is data to

js判断浏览器是关闭还是刷新

柔情痞子 提交于 2019-12-23 01:25:33
js判断浏览器是关闭还是刷新 对于ie,谷歌,360: 页面加载时只执行onload 页面刷新时,刷新之前执行onbeforeunload事件,在新页面即将替换旧页面时onunload事件,最后onload事件。 页面关闭时,先onbeforeunload事件,再onunload事件。 对于火狐: 页面刷新时,只执行onunload;页面关闭时,只执行onbeforeunload事件 刷新的时候先onbeforeunload,然后取服务端请求数据,在新页面即将替换旧页面时onunload事件,而页面关闭时,先onbeforeunload事件,再立即onunload事件。那么在刷新的时候,onbeforeunload与onunload之间的时间肯定比关闭的时候时间长,经过测试确实如此。 var _beforeUnload_time = 0 , _gap_time = 0 ; //_gap_time时间差 var is_fireFox = navigator . userAgent . indexOf ( "Firefox" ) > - 1 ; //是否是火狐浏览器 window . onunload = function ( ) { _gap_time = new Date ( ) . getTime ( ) - _beforeUnload_time ; if ( _gap_time

Call a function on page refresh using Javascript

谁说我不能喝 提交于 2019-12-22 10:57:26
问题 function warnuser() { return "Don't refresh the page."; } window.onbeforeunload = warnuser; If the user refreshes the page and the user clicks 'leave this page' on confirmation box, i want to call a javascript function , otherwise not! I am confused about how to do that. Thank you 回答1: You need to intercept the F5 key press and setup the onbeforeunload handler only in that case: document.addEventListener('keydown', function(e) { if(e.which == 116) { window.onbeforeunload = function() { window