window.onunload

I need to capture the window.onbeforeunload event

无人久伴 提交于 2021-01-01 18:37:01
问题 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 browser console window (maybe just for a second) but it is required otherwise it's not working. Example $(window).on('beforeunload', function(e) { $.ajax({ type: "POST", url: "url", data : {'value' : 1}, dataType:'json' }); return false; }); 回答1: The beacon API is meant specifically for that.

I need to capture the window.onbeforeunload event

帅比萌擦擦* 提交于 2021-01-01 18:36:13
问题 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 browser console window (maybe just for a second) but it is required otherwise it's not working. Example $(window).on('beforeunload', function(e) { $.ajax({ type: "POST", url: "url", data : {'value' : 1}, dataType:'json' }); return false; }); 回答1: The beacon API is meant specifically for that.

Javascript window.onunload fires off after Page_Load

别说谁变了你拦得住时间么 提交于 2020-01-23 14:41:08
问题 I have noticed that window.onunload event fires off AFTER page_load event which makes no sense. This behaviour is creating an issue for me - in my unonload I clear the session, so if the Page_Load first BEFORE onunload, there are errors on the page displayed. I would expect the javascript onunload to fire BEFORE Page_Load....is that the correct assumption? TO CLARIFY: Let's assume I am on page test.aspx, then I click on the link that goes to the same page (say I click on a menu), what I

Javascript window.onunload fires off after Page_Load

℡╲_俬逩灬. 提交于 2020-01-23 14:39:49
问题 I have noticed that window.onunload event fires off AFTER page_load event which makes no sense. This behaviour is creating an issue for me - in my unonload I clear the session, so if the Page_Load first BEFORE onunload, there are errors on the page displayed. I would expect the javascript onunload to fire BEFORE Page_Load....is that the correct assumption? TO CLARIFY: Let's assume I am on page test.aspx, then I click on the link that goes to the same page (say I click on a menu), what I

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

半世苍凉 提交于 2019-12-20 02:08:52
问题 Is there a way get the location for page being opened next in the window.onunload event. Best Regards, Keshav 回答1: No! That would be a security problem. Imagine someone navigating from a porn site to a banking site. The other way round (with the HTTP Referrer header) is already somewhat a headache. Firefox allows to suppress the referrer: Enter about:config in the address bar Search for referer (sic) Set network.http.sendRefererHeader to 0 (Courtesy to http://cafe.elharo.com/privacy/privacy

OnUnload Alert Error “NS_ERROR_NOT_AVAILABLE”

无人久伴 提交于 2019-12-19 19:55:09
问题 <html> <body> <button type="button" onclick="clickme()">Click Me</button> <script> var test = 0; function clickme() { test = 1; console.log(test); } window.onunload = function() { alert("test"); } </script> </body> </html> I'm using this simple code to test some things with onunload and onbeforeunload. For some reason whenever I refresh/leave the page and cause the onunload event I get no alert and an error in the Firebug console. If I use onbeforeunload this works and I get no error, but I

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

家住魔仙堡 提交于 2019-12-17 06:41:39
问题 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 this: window.onbeforeunload = function () { return "alert" }; However, if I substitute return "alert" with something like alert("blah"), I get nothing from Chrome. I saw in this question that Google purposefully blocks this. Good for them... but what if I want to make an

window.onbeforeunload handling ok and cancel options

北城余情 提交于 2019-12-13 04:43:28
问题 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 page. I want to save some data from the page when we press "ok" and move away from the page. How can we know if "ok" or "cancel" has been pressed , then make an event call and continue with the "ok"/"cancel" option. 回答1: function leavePage() { /

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

£可爱£侵袭症+ 提交于 2019-12-12 10:13:11
问题 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' window from a 'Parent' window and when the child window is closed/refreshed (i.e. when its unload event is triggered), it should also reload or refresh the parent window. Source code of parent.html file: <!DOCTYPE html> <html lang="en"> <head> <title

Javascript onclose event

非 Y 不嫁゛ 提交于 2019-12-11 11:43:42
问题 How can I run javascript when user close the browser. I tried to use 'onunload', but it calls every time I press F5/refresh button? Thanks 回答1: As far as the Javascript on the page is concerned, there's no difference between closing the browser, navigating to another page or refreshing the same page. 来源: https://stackoverflow.com/questions/6494206/javascript-onclose-event