I have a asp.net page in which I want to update database when browser close not tab close. I tried window.onbeforeunload event in JavaScript. It is working good enough when browser tab close but not giving desire result when Browser close in firefox only (not IE). What should I do in this circumstance?
Related
I want an event that work when I close browser only (not close tab or reload page).
I am using the following code :
$(window).on("unload",function(){
localStorage.clear();
});
I have tried onunload & onbeforeunload, it works for close browser, reload page, close tabs, but for me I want an event that affects only close browser. Any recommended event (close browser only) for me.
You can only detect an unload of a page, not closing of the browser. It just cannot be done.
There's no such event that exclusively works on browser close.
I am trying to detect browser or tab close event for Chrome, so that I can invalidate the session for my Java web application. I have tried onbeforeload() and unload(), but these functions are called when the content of page is unloaded within my web application. Also I am unable to override these functions in Javascript for Chrome browser.
Is there any way I can find browser close or tab close event for Chrome and make an ajax call and invalidate the session?
I know there are many links regarding Onbeforeunload,BeforeUnload and Onunload events of JavaScript which have some cross browser problems. After going through, possibly, all the questions, I want to ask this again
Is there any way so that onunload can work for Chrome and Opera?
I don't want to use onbeforeunload as it pops up before closing window.In my application user clicks a "Save And Exit" button after which an alert box is popped up showing "Your details are saved" with OK button. clicking on OK button redirects user to a new popup asking the window is about to close with yes and no buttons. onbeforeunload event as returns a string, hence it doesn't allow me to show the "AlertBox" asks for leave this page and stay on this page. which is not in alliance with my application requirement as i want as alert box. (working fine in IE, not working in Opera and chrome).
i am using unload and onbeforeunload events from code behind c#
I am facing a wired scenario in Firefox 4. When I close the tab window.onbeforeunload is getting called. But when user is closing the window by the cross bar it is not getting called.
Is that a bug in Firefox or there is some other thing I need to do . Please check my code.
$(document).ready(function(){
window.onbeforeunload = function(){signout()};
});
window.onbeforeunload = function(){signout()};
Even writing this code outside document.ready is also not working. The same code is working on chrome.
The scenario get's even wired when their are more than one tabs are opened and then user closes the window (not the tab) by cross bar. In this scenario , Firefox asks the user to confirm that he is closing two tabs and after that my code works !!!. This is quite surprising my code does not work only when my page is the only tab and the user closes the window.
There's a thread on it here:
window.onunload only fires when a tab is closed in firefox, not the entire browser
It looks like it was a feature around that time to prevent unscrupulous websites from preventing browser being fully closed. I wouldn't be surprised if this is still the case, but the only way to find out is to try on a more current version of Firefox.
I have this solution that takes the user through a series of questions. At the end the user can click a button that opens a new window with a form to enter contact info. The population of this popup window is done through JavaScript from the calling window.
The process (in JS) is this:
Open popup window with loading gif
Store additional information remotely through ajax
Populate popup window with contact form
This all works fine in desktop browsers but not on iPads (using Safari where all windows are displayed as tabs). I have a suspicion that the JavaScript in the parent tab is halted when the "popup" tab gets displayed. To support this theory I can actually get the popup tab populated if I switch back to the parent tab immediately after the popup tab is displayed.
Can anyone confirm this? And of course if there's a solution I would very much like to hear about it.
Needless to say it works like a charm on my Android tablet :-)
Try using window focus and blur to activate some javascript when the focus is back on your tab.
See: https://stackoverflow.com/a/3479936/1712686