Questions tagged [window.onunload]

The window object in JavaScript has an event handler called onload . When this event handler is used, the entire page and all of its related files and components are loaded before the function listed in the onload event handler is executed, hence the term "on load."

77 questions
38
votes
7 answers

window.onunload is not working properly in Chrome browser. Can any one help me?

I have written this code function winUnload() { alert("Unload Window"); MyMethod(); } window.onunload = function() { winUnload(); } This code is working fine in IE and Firefox. But this code is not working in Chrome. Both the…
Imran
  • 389
  • 1
  • 3
  • 4
29
votes
5 answers

window.onbeforeunload in Chrome: what is the most recent fix?

Obviously, window.onbeforeunload has encountered its fair share of problems with Chrome as I've seen from all the problems I've encountered. What's the most recent work around? The only thing I've got even close to working is…
varatis
  • 14,494
  • 23
  • 71
  • 114
17
votes
3 answers

Capturing result of window.onbeforeunload confirmation dialog

Is there a way to capture to result of the window.onbeforeunload confirmation dialog like the one below from Stack Overflow (this happens when leaving the 'Ask Question' page without posting the question)? This is how it appears in Chrome, I believe…
xzyfer
  • 13,937
  • 5
  • 35
  • 46
14
votes
4 answers

Why does window.open(...).onunload = function () { ... } not work as I expect?

I want to be able to tell when a window that I open is closed by the user. This is the code of my attempt at monitoring this:
Steven Oxley
  • 6,563
  • 6
  • 43
  • 55
10
votes
4 answers

Is there a way to call a method upon leaving a page with JSF or PrimeFaces?

Is there a way to call a method upon leaving a page with JSF?
Landister
  • 2,194
  • 7
  • 38
  • 56
5
votes
0 answers

Detect when chrome extension popup closes and save data

I'm trying to prevent loss of information when the user doesn't press Save and the chrome extension popup is closed or navigates away to a different tab. I save the text from the popup and put it back once the popup is opened again. So, I have this…
5
votes
1 answer

OnUnload Alert Error "NS_ERROR_NOT_AVAILABLE"

I'm using this…
Cains
  • 883
  • 2
  • 13
  • 23
4
votes
3 answers

window.onbeforeunload handling ok and cancel options

I have a window.onbeforeunload function which generates the default message: "Are you sure you want to navigate away from this page...." . If we click on OK we are redirected to a new link and if we press cancel we are redirected back to the same…
prateek
  • 41
  • 1
  • 2
3
votes
0 answers

javascript (window).unload in not working for certain chrome versions

The following method of window.unload works fine on different browsers and some browsers of chrome as well but does not work on particular chrome browsers. $(window).unload(function () { var tabSessionId = getUrlVars()["info"]; var…
3
votes
2 answers

window.onunload only fires when a tab is closed in firefox, not the entire browser

UPDATE So after reading both of your answers I realize there is no reliable way to determine when a browser window is closed. Originally I was planning to use this to unlock a record in the database when the page is closed. Basically when the user…
ryanulit
  • 4,983
  • 6
  • 42
  • 66
3
votes
2 answers

Get url for the page being opened next in window.onunload event

Is there a way get the location for page being opened next in the window.onunload event. Best Regards, Keshav
keshav84
  • 2,291
  • 5
  • 25
  • 34
3
votes
3 answers

Popup message when leaving page

I am looking to develop a small popup message which acts similar to the window.beforeunload function, to notify the user, that if they leave the current page, they will lose all of their data. However the issue with the beforeunload event is it…
Ben_hawk
  • 2,476
  • 7
  • 34
  • 59
2
votes
1 answer

location.href does not work in chrome when called through the body/window unload event

Javascript - document.location or window.location or window.location.href or location.href does not work in Google Chrome 6 and 7(i didnt test lowers versions) when called from the window/body unload event. Both the ways seems to work fine with IE,…
Nived
  • 21
  • 1
  • 3
2
votes
1 answer

JavaScript - send AJAX call on tab close (DELETE request)

I want to send an AJAX DELETE request through Javascript when the user closes the tab. The flow is the following: When the user attempts to close the tab, a onbeforeunload event takes place, then if the user confirms to leave the page the onunload…
NickAth
  • 1,089
  • 1
  • 14
  • 35
2
votes
1 answer

Javascript 'onunload' event not working in latest Version '54.0.2840.71 m' of Google Chrome browser

Recently I updated my Google Chrome browser to Version '54.0.2840.71 m' and suddenly javascript 'onUnload' event has stopped working. I am sure, it was working fine before the upgrade. In my code (mentioned below), I am trying to open a 'Child'…
Sam
  • 63
  • 1
  • 7
1
2 3 4 5 6