onbeforeunload

ASP.NET, jQuery, dirty forms, and window.onbeforeunload

依然范特西╮ 提交于 2019-11-30 07:27:20
问题 In my ASP.NET web app, I'm trying to create a universal way of warning users before navigating away from a form when they've made changes, using jQuery. Pretty standard stuff, but after a lot of searching I have yet to find a technique that works. Here's what I have at this point: addToPostBack = function(func) { var old__doPostBack = __doPostBack; if (typeof __doPostBack != 'function') { __doPostBack = func; } else { __doPostBack = function() { old__doPostBack(); func(); } } } var isDirty =

Internet Explorer calling window.onbeforeunload on window.open and AJAX calls

纵然是瞬间 提交于 2019-11-30 02:56:18
问题 Ok, I have spent a while on this problem and this is what I have gathered: If you make an AJAX call in IE7 and you have a window.onbeforeunload function specified, it calls the onbeforeunload function. If you try to open a new window with window.open WITHOUT disturbing the current window, the onbeforeunload gets called. Does anyone know how to stop this? I even tried setting a variable to TRUE and check that variable in my onbeforeunload function and it still dosent work! I just need to be

How to collect return value of onbeforeunload

馋奶兔 提交于 2019-11-30 02:28:32
问题 I am displaying a warning message if user try to close window without saving the form. window.onbeforeunload = askConfirm; function askConfirm() { // needToConfirm is set to true if any changes are there in the form if (needToConfirm) { return "Your unsaved data will be lost."; } } function call_this_if_user_clicks_on_cancel() { // Bla bla bla // After this user should remain on the same page. } Now I want to call another function when user clicks on Okay . And rest of the functionality

Can I prevent window.onbeforeunload from being called when doing an AJAX call

混江龙づ霸主 提交于 2019-11-29 22:23:45
I have an AJAX-based grid control. We hook into the window.onbeforeunload event to check if they have unsaved data and if so present them with a message "Are you sure you want to navigate away...you have unsaved data...". All this is good. But AJAX calls also trigger window.onbeforeunload and so if the grid has unsaved data and we make an AJAX call (such as to delete a row in another grid) the user gets the "Are you sure you want to navigate away...you have unsaved data..." message which is not good. Is it possible to suppress the onbeforeunload event for AJAX calls? Or is it possible to

onbeforeunload与onunlond的区别

拟墨画扇 提交于 2019-11-29 20:30:24
1.onbeforeunload:的意思是在刷新或页面后台的情况下 会出现这样一个弹窗 有两种情况第一是刷新页面的时候你点击离开就回到本页面 点击浏览器后退按钮是 点击离开会返回到上一级页面 <script type="text/javascript"> <!-- window.onbeforeunload = onbeforeunload_handler; //window.onunload = onunload_handler; function onbeforeunload_handler(){ var warning="确认退出?"; return warning; } // --> </script> 2onunlond:意思只是单纯的刷新页面的时候触发的某些东西 <script type="text/javascript"> <!-- window.onunload = onunload_handler; function onunload_handler(){ var warning="谢谢光临"; alert(warning); } // --> </script> 就弹出一般的alert 谢谢光临 来源: oschina 链接: https://my.oschina.net/u/723177/blog/73756

beforeunload on Chrome

柔情痞子 提交于 2019-11-29 18:04:41
I have this code that will redirect the user to another URL whenever he/she closes the page. This is working on Firefox, IE, Safari, etc. but not in Chrome. It won't redirect the user to new URL. Thanks! jQuery(document).ready(function() { jQuery(window).bind('beforeunload', function(e) { location.href="http://google.com/"; return "Before you leave, please take a look at this limited time offer."; }); }); Not sure it is what you are looking for, this will redirect user if he choices to stay on page: DEMO var a,b; window.onbeforeunload = function (e) { if (b) return; a = setTimeout(function ()

Chrome / Firefox doesn't display images in objects shown in beforeunload event

…衆ロ難τιáo~ 提交于 2019-11-29 17:28:03
I'm using jQuery blockUI plugin to show some nifty "loader" on each AJAX call and each URL change. Here is full code responsible for that: var rootPath = document.body.getAttribute("data-root"); $.blockUI.defaults.message = '<h3><img style="margin: 0 5px 5px 0" src="' + rootPath + '/images/process.gif" width="48" height="48" />In progress...</h3>'; $.blockUI.defaults.css.top = '45%'; $(document).ajaxStart($.blockUI).ajaxStop($.unblockUI); $(window).on('beforeunload', function(){$.blockUI();}); Everything is fine during AJAX call, however, I've noticed that Chrome and Firefox does display

How to handle below Internet Explorer popup “Are you sure you want to leave this page?” through Selenium

て烟熏妆下的殇ゞ 提交于 2019-11-29 17:05:59
How to Handle below IE Popup in Selenium The Internet Explorer popup with text as Are you sure you want to leave this page? is the result of WindowEventHandlers.onbeforeunload onbeforeunload The onbeforeunload property of the WindowEventHandlers mixin is the EventHandler for processing beforeunload events. These events fire when a window is about to unload its resources. At this point, the document is still visible and the event is still cancelable. Solution There are different strategies available to handle this popup . However, as a Cross Browser solution, you can disable this dialog

window.onbeforeunload executed on page refresh instead of on page close

谁都会走 提交于 2019-11-29 09:42:22
I'm using window.onbeforeunload to pop up a confirm dialog when a close event occurs, but the confirm dialog appears on page refresh and doesn't execute on page close. Here's the JavaScript code: <script language="JavaScript"> window.onbeforeunload = confirmWinClose(); function confirmWinClose() { var confirmClose = confirm('Close?'); return confirmClose; } </script> I tried it on Chrome, Firefox and Internet Explorer. PROBLEM WITH YOUR CODE: the function will be called when you refresh , because on refresh the page is unloaded and then reloaded . in your solution, you should also note that

PHP update database on close window

我的未来我决定 提交于 2019-11-29 09:02:04
I am trying to update the database when the user close or refresh the browser. This is my code: $(window).bind('unload', function(){ $.ajax({ type: 'get', async: false, url: 'liberaLugar.php?idCurso=2' }); }); Any help will be appreciated. Thanks in advance! This should work for you in most cases. of course, if your server is unreachable, you could freeze the browser, so we should also add a timeout. it may also be helpul to give your user some visual indicator of what the hell is going on, so we should set the cursor to waiting. var unloaded = false; $(window).on('beforeunload', unload); $