Questions tagged [onunload]

The tag has no usage guidance.

onunload
Filter by
Sorted by
Tagged with
2 votes
1 answer
344 views

Back button not triggering JS on Chrome

I have a horizontal scrolling website that you drag by clicking and dragging with the cursor. On load the page should load in the middle of the scroll and you can drag it left and right. It works when ...
AJH's user avatar
  • 31
0 votes
0 answers
82 views

JS onbeforeunload runs unconditionally to user's selected choice

I have a very simple code: window.onbeforeunload = function(e) { console.log("closing"); e.preventDefault(); try { self.recorder.stop(); } catch (err) { console.log(err); } ...
The Blind Hawk's user avatar
0 votes
0 answers
700 views

Is it possible for us on javascript to detect on the event beforeunload/unload if its a refresh or leave?

// This might seem to be a duplicate question, but all the questions I have found were old and was wondering if there is any new functionality available in the latest browsers Requirement: Identify if ...
tony's user avatar
  • 61
1 vote
1 answer
2k views

Async Event on Tab Close

I'm looking for a solid solution to carry out an asynchronous event on a tab close in JavaScript For context, I have a site with multiple (thousands) of pages that should only allow one user to edit a ...
mmarion's user avatar
  • 933
0 votes
0 answers
289 views

JavaScript: Handle unload event on redirect

Am trying to handle unload event on browser redirect (e.g. redirect on a button click), but it seems it is not getting triggered. I can see beforeunload being triggered, but not unload one. Is there a ...
hack's user avatar
  • 1,503
0 votes
1 answer
4k views

Detect Page Refresh or Navigation in Browser

I have a web app where a parent page displaying a list of records opens up a new tab ('child') to edit a clicked-on record. I want to track who has a page open, so I can display a message if more than ...
Ben McIntyre's user avatar
  • 1,946
0 votes
1 answer
1k views

Chrome and beforeunload/unload

I have a seemingly simple requirement but I have been stuck for days. Can someone give me a hand? I need a confirmation prompt if the user tried to close the pop-up window if the user click ok to ...
Adrian Pang's user avatar
  • 1,135
0 votes
1 answer
76 views

js save data on page unload does not work as expected

Im trying to save some data on page unload, this is my current script window.addEventListener("unload", function(event) { if(snippetChanged){ //save it snippetChanged = ...
user avatar
1 vote
1 answer
851 views

onbeforeunload not/not correct working in Javascript

I'm trying to use the onbeforeunload or onunload event or even in a: window.addEventListener('beforeunload', function(){alert("3");}, false); but it doesn't work, neither on Chrome nor on ...
ebm9991's user avatar
  • 13
3 votes
1 answer
10k views

Fetch Keep Alive is not working as expected

I am working on AngularJS 1.6 version. In my app.controller.js I have added three event listeners and attached a deleteStudent method. window.addEventListener('beforeunload', this.deleteStudent, false)...
Akshay's user avatar
  • 31
0 votes
0 answers
450 views

'onunload' event to close a popup window

I am using the following code to generate a images on a page (from a passed array in an .ejs page) and a 'popup' window on a page when an image is 'clicked': addEventListener("load", initialize); ...
Pangit's user avatar
  • 624
0 votes
1 answer
226 views

Window.onUnload inconsistently sends results to server

I am trying to have the user get an alert when they try to leave the page, and make a post request if they leave, if not, do nothing. Here is my code (using JQuery): $(window).on("unload", ...
imaginate's user avatar
  • 569
1 vote
0 answers
27 views

How can I send a synchronous ajax request to my server in onunload function

I need to send a ajax request to my server before web page close, my send code is below. SendByAajx = function(msg) { var response; var xmlHttpReg; if(window.XMLHttpRequest){ ...
John's user avatar
  • 41
7 votes
2 answers
5k views

Closing Chrome window not sending data with sendBeacon in unload event handler

I am trying to send data when the window closes to prevent 2 people from editing and overwriting each others data. Currently I am using a sendBeacon within a unload event handler. FireFox: Refresh: ...
webdevtrev's user avatar
2 votes
0 answers
1k views

Changing dynamic sound src in howler.js has problems

I've added buttons to the page that when you click on each one, it first unloads the howl object and changes the src, and then new music is played. But the problem is that after changing src twice, ...
ISPOOYA's user avatar
  • 21
0 votes
1 answer
203 views

trigger unload event in iframe app when parent application tab closes

I have two apps, App1 and App2. App2 is embedded as an iframe in App1, so App1 is parent app which embeds App2. When user closes App1 from browser, I want to trigger an api in App2. I tried using '...
hack's user avatar
  • 1,503
0 votes
1 answer
928 views

beforeUnload does not call

I have a react app where I want to delete a user from the database if he leaves the session. I tried doing that with onUnload but it doesn't call the method at all. Part of the code that is relevant: ...
Dani's user avatar
  • 576
0 votes
1 answer
2k views

Xamarin.Forms Cannot call OnDisappearing()

I need to just show a message (Under certain circumstance) when I'm leaving a screen. Found that there's a method called OnDisappearing() that is called when the form is being unloaded (Or also being ...
Jorge Lizaso's user avatar
0 votes
0 answers
482 views

Microsoft Edge is unable to set localStorage when unload event

I have stucked this issue for a month. Anyone who knows the solution, please help. I would like to close all child window if the main window is closed (click 'X' button on tab or browser window) ...
Andrew J's user avatar
2 votes
1 answer
3k views

navigator.sendBeacon not called from unload

According to MDN and the specs, navigator.sendBeacon is intended to be called from window unload. Now, it does not seem to work anymore if you close the last tab of your browser, or your entire ...
Casper's user avatar
  • 73
0 votes
2 answers
633 views

Are there any conditions under which window.unload event does not fire?

I'm using navigator.sendBeacon on the front end to tell the server when a user enters and leaves a page (via window.load and window.unload). I'm recording the time of arrival/departure server-side. I'...
wrkyle's user avatar
  • 539
0 votes
1 answer
1k views

Message for quitting a page only working with Edge and not Chrome and Firefox

I am currently working on a website and there is a page with a form. When the user tries to leaves this page, I want a confirmation message to show up. This is how I did it: In the JSP file (the ...
Gaëtan's user avatar
  • 789
1 vote
1 answer
2k views

I need to capture the window.onbeforeunload event

I am working on a project where I need to capture the browser close event (unload or beforeunload). For that I have tried the code below but it's not working. The code is working only if I open the ...
Sunil Bamal's user avatar
0 votes
0 answers
56 views

window.onunload and Ajax Navigation

I'm trying to insert an onunload event into a page. function onUnload(){ console.log("GOODBYE"); //TODO: insert Function here } window.onunload = onUnload; It works and I am greeted ...
bloodfire1004's user avatar
5 votes
2 answers
5k views

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 ...
Chronus's user avatar
  • 301
0 votes
0 answers
1k views

How to run code after window opened with "window.open" is closed?

I opened a window using window.open and go the reference to it. By using windowRef.window.onunload = () => this.afterWindowUnloaded.emit(this.data); I can watch the reload of the page, but can't ...
KaomiDev's user avatar
0 votes
0 answers
142 views

Javascript window unload

I want to detecting if tab/window is close, if true will trigger to logout.php page. So I had this script. var unloaded = false; $(window).on('beforeunload', unload); $(window).on('unload', ...
dontbannedmeagain's user avatar
1 vote
1 answer
571 views

Capturing the browser tab reload and tab close functionality

I want to call an ajax to other pages on the browser or tab close. When we reload tab or close tab it calls onbeforeUnload and onUnload events. If I reload page either by pressing ctrl+r or by ...
user9261589's user avatar
0 votes
2 answers
2k views

How to call an external function inside onbeforeunload() if the user chooses to move out of the page?

I've seen many examples and tried them out where the specified function gets called if the user decides to stay in the page. I need to call an external function just before the page is unloaded, if ...
arjunkm's user avatar
  • 471
-1 votes
1 answer
2k views

Calling an http request in an window:unload handler in Angular 5

I have an application which needs to make sure the user has saved their data when they accidentally close the browser (or tab). I have added a window:beforeunload handler to show the confirm dialog ...
KenPx's user avatar
  • 39
1 vote
0 answers
179 views

Cleanup in WebWorker when page is closed

I have a WebAssembly module running in a WebWorker. This module contains a session key for encryption and other sensitive data I want to memzero before the page is closed. Is there any way to ...
kamulos's user avatar
  • 319
0 votes
0 answers
55 views

windows.onunload not working on chrome

I am currently doing a project using an eyetracking tool where when the student clicks on an exercise, it will start recording the eye gaze patterns and when the student navigates away from the ...
wendyrurt's user avatar
0 votes
1 answer
1k views

How to show dialog box if user wants to close the browser and then check what they selected?

I'm wondering if there is any solution in JavaScript or JQuery to show the message to the user if they want to close their browser/window? I know there is an option to use beforeunload but the only ...
espresso_coffee's user avatar
1 vote
1 answer
617 views

Closing many pop-up windows on unload

Here is my website : http://www.brute.adult. And here is the codepen : https://codepen.io/vaninoo/pen/GMbbEg. As you can see on the website, when you click on links, many pop-ups appear. I've been ...
Vanille A.Nour's user avatar
2 votes
0 answers
346 views

Chrome unload event when Browser is closed

I am attempting to hookup the "unload" event to perform cleanup when the user navigates away from my page. In order to achieve this, synchronous requests are used - the following code is used: ...
Guillaume's user avatar
0 votes
0 answers
386 views

Chrome onUnload event not triggering

I have set something in local storage (where tabId is the id of the triggering tab [onUpdated event]) var visited = {}; visited[tabId] = true; chrome.storage.local.set(visited); I then wish to ...
Stephen Keeton's user avatar
0 votes
0 answers
77 views

unload function listening to both refresh and close

I am trying to catch a event i.e. window close. So i used unload, but it catches both refresh and close. So my action gets triggered for both. Is there a way to catch only close event?
Hacker's user avatar
  • 7,856
1 vote
1 answer
1k views

Redshift UNLOAD statement get's canceled after 19min

I'm trying to UNLOAD to s3 a large (6GB) data set using this utility (https://github.com/awslabs/amazon-redshift-utils/blob/master/src/UnloadCopyUtility/redshift-unload-copy.py) from an EC2 instance. ...
Johny19's user avatar
  • 5,454
-1 votes
1 answer
129 views

Beforeunload Function is Not working And not updating the records after unload

Here is my code function myfoo() { $.ajax({ type: "POST", url: "update.php", dataType: 'json', async: false, data: { Eventid: 1, Seats: 'Seats' }, success: ...
krish's user avatar
  • 120
0 votes
0 answers
176 views

object.onunload does not work properly in internet explorer

I was wondering why my codes works fine in chrome but it won't work in IE. I believe object.onunload works in IE too. function showPopup() { myPopup = window.open("", "", "dialogWidth:500px;...
Cille's user avatar
  • 113
0 votes
0 answers
106 views

Workaround for Firefox's lack of support of onUnload?

We have a chat client in our web app. When the user closes the window the chat is in, we provide a chance to cancel in the onBeforeUnload event $(window).on('beforeunload') = function(e) { return (...
Garrett Daniel DeMeyer's user avatar
0 votes
1 answer
68 views

I want a form to be completed when the user exits the site

I have some code that gets the user to enter some information and I want that information to be submitted when the page is closed (just to be different) but at the moment, it only gets submitted if ...
D.Drew's user avatar
  • 1
1 vote
0 answers
527 views

javascript function to execute AFTER browser back button is clicked

Is there a way to trigger an event AFTER the browser back button is clicked? The event will happen AFTER the previous page has been loaded and NOT BEFORE the user exits the current page. From my ...
GibiDroidZ's user avatar
1 vote
0 answers
689 views

localStorage usage only on page load and unload - good practice?

Let's say I have a name value on the page. The user can change it at any time. The only requirement is that when the user leaves the page and comes back, name should be whatever it was last time. ...
dodov's user avatar
  • 5,460
1 vote
2 answers
3k views

How to change the text of “Are you sure you want to leave this page?” function script of "onunload"?

How to change the text of this function script?: window.onbeforeunload = function(e) { return 'Are you sure you want to leave this page? You will lose any unsaved data.'; }; ...
bloodstriker's user avatar
5 votes
2 answers
2k views

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 ...
Scotty H's user avatar
  • 6,574
1 vote
2 answers
1k views

Javascript / angular: perform asynchronous http from onunload

I'm working with a web app that locks resources on a server. To unlock them, it has to delete a resource on the server with an HTTP DELETE. I know this isn't reliable and there's a periodic cleanup ...
Rogerborg's user avatar
  • 153
3 votes
0 answers
2k views

window.location.href not working on beforeunload and unload

Hello all am trying to redirect user to redirect to another page when user decides to reload if he is asked for confirmaton. The function are getting executed but the window.location.href seems not to ...
santoshu's user avatar
0 votes
1 answer
220 views

Trying to send data cross domain on page exit with javascript

I have a script on multiple domains that are not mine which sends data to an AWS SQS queue on page exit. When I compare the number of times I receive data to the number of times that the script is ...
Keith C.'s user avatar
  • 375
0 votes
0 answers
59 views

Mail or submit filled form data on page close or page unload

I want to submit or mail the fully filled or partially filled form data when the user closes the page or hit the back button of the browser. Is it possible to create such an environment using jQuery ...
Jomon Joseph's user avatar