onbeforeunload

Detecting whether user stayed after prompting onBeforeUnload

半城伤御伤魂 提交于 2019-11-27 03:32:49
问题 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

Can I pop up a confirmation dialog when the user is closing the window in Safari/Chrome?

谁说我不能喝 提交于 2019-11-27 02:15:50
In IE and FF, i can attach an event handler to onBeforeUnload, and by passing a string to a property of the event, the user will see a dialog asking him whether he wants to continue with the "unloading" (either closing the window or navigating away). Safari and Chrome don't support onBeforeUnload, and onUnload seems to be too late. Is there some way to replicate the same functionality in Safari/Chrome? NOTE: I'm not trying to keep the user hostage. I know this is nagging and un-cool. In fact, my site goes to great lengths to let the user go freely, and have everything in its place when they

Difference between onbeforeunload and onunload

耗尽温柔 提交于 2019-11-27 01:32:58
What are the differences between onbeforeunload and onunload ? Also I have a specific question related to it's use on the iPad...I have a page (myPage.html) where I am trying to show an alert when the page is closed (i.e. X is pressed to close the tab on iPad) Now I tried using both window.onunload and window.onbeforeunload Below are my findings on the iPad; Using window.onunload , I am able to get an alert when user navigates to a different page from myPage.html (either by clicking on some link or doing a Google search while on myPage.html) . However nothing happens when the tab is closed

Javascript detect closing popup loaded with another domain

青春壹個敷衍的年華 提交于 2019-11-26 22:40:41
问题 I am opening a popup window and attaching an onbeforeunload event to it like this: win = window.open("http://www.google.com", "", "width=300px,height=300px"); win.onbeforeunload = function() { //do your stuff here alert("Closed"); }; If I leave the URL empty, the new popup opens with "about:blank" as the address but when I close it, I see the alert. If I open in as you see it (with an external URL), once it's closed, I cannot see the alert anymore. Any idea why this is happening? 回答1: As

how to identify onbeforeunload was caused by clicking close button

不问归期 提交于 2019-11-26 22:05:59
问题 How do I determine if onbeforeunload was caused by clicking the close button or a page refresh or generally what event caused onbeforeunload? here is a snippet: window.onbeforeunload = function( e ){ if( !e ) e = window.event; // insert code to determine which is the source of the event } Please help me. 回答1: Referring to various articles and doing some trial and errors, finally developed this idea which works perfectly for me just the way i wanted it to happen. The logic was quiet simpler it

onbeforeunload in Opera

情到浓时终转凉″ 提交于 2019-11-26 21:47:37
问题 I'm using the code that netadictos posted to the question here. All I want to do is to display a warning when a user is navigating away from or closing a window/tab. The code that netadictos posted seems to work fine in IE7, FF 3.0.5, Safari 3.2.1, and Chrome but it doesn't work in Opera v9.63. Does anyone know of way of doing the same thing in Opera? Thx, Trev 回答1: onbeforeunload is now supported in Opera 15 based on the WebKit engine but not in any prior versions based on Presto. 回答2: Opera

Is there any way to use window.onbeforeunload on Mobile Safari for iOS devices?

 ̄綄美尐妖づ 提交于 2019-11-26 20:19:58
Looks like Apple has disabled the window.onbeforeunload event for iOS devices (iPhone, iPad, iPod Touch). Unfortunately I can't find any documentation as to why this event doesn't work in Mobile Safari. Does anyone know if there's a reliable alternative to this function? Android's browser appears to support it just fine, and the Safari desktop application also supports the onbeforeunload event without issue. Miquel I see that it's an old question, but i faced this problem recently. I'm using window.unload and it works fine in ios browsers (although if you look at Apple documentation it seems

Setting onbeforeunload on body element in Chrome and IE using jQuery

本秂侑毒 提交于 2019-11-26 17:59:05
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 it. if ($("body").attr('onbeforeunload') == null) { if (window.event) { // IE and Chrome use this $(

JavaScript + onbeforeunload

半腔热情 提交于 2019-11-26 17:48:27
问题 I have a query regarding my application. Whenever user closes browser window accidentally I'd want to do some clean up operations before that. I have used onunload event but problem is this event is sometimes is firing and sometimes doesn't. What should I do, is there better way to handle such type of problem. 回答1: window.onbeforeunload = function() { return 'You have unsaved changes!'; } See the MSDN article on onbeforeunload Also there is a similar question in SO 回答2: Try: window

Reload the site when reached via browsers back button

孤街醉人 提交于 2019-11-26 17:40:43
问题 Problem: I have a site with dynamic content which needs to be reloaded every time the user sees it. This includes the use case when a user hits the back button on an another site and comes to the site needed to be reloaded. Most (all?) browsers don't refresh the site after this event. My solution (which isn't quite working): http://www.hunlock.com/blogs/Mastering_The_Back_Button_With_Javascript window.onbeforeunload = function () { // This function does nothing. It won't spawn a confirmation