Questions tagged [onunload]

198 questions
6
votes
5 answers

Don't have time to send get request on window unload

I want to notify the server on user closes browser window. I tried all of the $(window).bind("beforeunload", function() { $.get("${contextPath}/notify?direction=logout"); }); and $(window).unload( function() { …
Dims
  • 47,675
  • 117
  • 331
  • 600
6
votes
4 answers

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

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…
Daniel Magliola
  • 30,898
  • 61
  • 164
  • 243
6
votes
1 answer

Rails 3 form helper to prevent user from navigating away and losing changes?

Is there a Rails helper or a Rails way of preventing the user from leaving the current page if they're typed something into the form on the current page? I'm trying to prevent people from losing data if they click a header link if they have unsaved…
Amy
  • 1,318
  • 3
  • 12
  • 24
5
votes
1 answer

How to trigger onunload event when removing iframe ?

How can the iframe's unload event be triggered when removing it? Using the code below, when removeChild(iframe) is called, the onunload event is not triggered. remove iframe
consatan
  • 349
  • 1
  • 7
  • 18
5
votes
4 answers

Detecting browsers that don't support onunload/onbeforeunload

Of all the browsers, it seems that only Opera doesn't support onunload/onbeforeunload events. (It's been fifteen years now, Opera!) Solutions for this issue have been covered many times, here for example: onbeforeunload support…
5
votes
2 answers

Perform an asynchronous service get when closing browser window / tab with Angular

I'm currently trying to make an Angular app make an API service call when the user tries to navigate away from my page. Either by closing the tab / window, or typing in an external URL. I've tried to implement several different ways I've seen…
Chronus
  • 301
  • 3
  • 17
5
votes
5 answers

JS onunload event won't always work

I want to count how much time visitors spend on a certain page and store it in my MySQL DB. I thought of just starting a timer on window.onload like this: window.onload= startCount; window.onunload= sendCount; var b=0; var y; function startCount()…
LightDark
  • 73
  • 1
  • 6
5
votes
2 answers

Call a POST request for logging from window unload

I have been struggling to write code that will make a POST request reliably on close of the tab window. Navigator.sendBeacon seems to be exactly what I need (I only require this to work for Google Chrome). $(global).bind('unload', function () { …
Scotty H
  • 6,432
  • 6
  • 41
  • 94
5
votes
2 answers

confirm before onbeforeunload

I need to prompt the user before he leaves the page, on confirmation close the tab and if not do nothing. I want to send an ajax call on onbeforeunload. My only idea was to write handlers for both onunload and onbeforeunload like this:…
Nikita240
  • 1,377
  • 2
  • 14
  • 29
5
votes
1 answer

OnUnload Alert Error "NS_ERROR_NOT_AVAILABLE"

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

Show popup window when the browser close

I'm developing an eCommerce(PHP) web site and here's my requirement. Once the customer leave the order page or close the browser, I would like to offer another product with pop up or alert box. If they choose 'Yes', it will redirect to another…
Den
  • 369
  • 1
  • 4
  • 12
4
votes
3 answers

Strategies for preserving form data ( on tab/browser close )

I have an issue with a task management application where occasionally users close their browsers/tabs and the information which they type goes away because they accidentally close a browser/tab, resulting in the loss of the text which they've…
meder omuraliev
  • 183,342
  • 71
  • 393
  • 434
4
votes
3 answers

What happens to Javascript when page navigates away?

What happens to Javascript when page navigates away? A book I am reading is instructing to clear things on "unload" event. But what's the point? doesn't everything get lost and released when pages moves away in browser? Thanks, Sean
born2net
  • 24,129
  • 22
  • 65
  • 104
4
votes
0 answers

onUnload firing after page load when refreshing page

I've found something very strange and I'm quite amazed, I wonder if someone has found it before or could imagine what's hapenning. I have an ASP.NET MVC3 chess application. Now I'm developing a lobby for users to join and send match invites to…
Bardo
  • 2,470
  • 2
  • 24
  • 42
3
votes
1 answer

How to do ajax synchronous call from Chrome's window.onunload?

I'm trying to do a jquery .ajax synchronous call on window.onunload. FF and IE works but not on Chrome. I had done some testing and Chrome seems to terminate the window and not wait for the response. Here is my code: window.onunload = function() { …
deepsweech
  • 31
  • 4
1
2
3
13 14