window.onunload

img requests before windows close

£可爱£侵袭症+ 提交于 2019-12-11 04:07:43
问题 I have the situation that data needs to be reliably sent before browser window closes. My current implementation is to use a synchronous AJAX calls. However that's unlikely to work in the near future because the browsers are deprecating synchronous XHR calls according to https://xhr.spec.whatwg.org/#synchronous-flag What I'm trying is to replace the ajax call with a fake "img" call, parameterize data to be sent and append it as the image's url query string. It seemed to work so far I tried. I

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

☆樱花仙子☆ 提交于 2019-12-11 02:05:55
问题 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, Firefox and Safari browsers. Through more testing i was able to see that this redirect actually works in chrome when done through a click event or any other. However when this is called in the body unload event. it does not work. Sample Code: <html

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

北战南征 提交于 2019-12-06 15:53:43
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>Parent Page</title> </head> <body> This is parent page. Click <a href="#" onClick="window.open('child

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

血红的双手。 提交于 2019-12-05 15:44:33
问题 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: <html> <head> <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script> <script type="text/javascript"> window.document.onready = function () { document.getElementById('openWindow').onclick = function () { var windowref = window.open('tests2.html'); windowref.onunload = function () { window.alert('hola!'); }; }; }; </script> </head>

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

送分小仙女□ 提交于 2019-12-03 18:02:40
问题 Is there a way to call a method upon leaving a page with JSF? 回答1: Not when using native JSF or PrimeFaces. Your best bet would be to hook on session expiration instead. import javax.inject.Named; import javax.enterprise.context.SessionScoped; @Named @SessionScoped public class Bean implements Serializable { @PreDestroy public void destroy() { // Your code here. } } If you happen to use the JSF utility library OmniFaces, then you can use its @ViewScoped. This will call the @PreDestroy when

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

 ̄綄美尐妖づ 提交于 2019-12-01 21:37:52
Is there a way get the location for page being opened next in the window.onunload event. Best Regards, Keshav 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-tip-3-block-referer-headers-in-firefox/ ) The current page cannot and should not know where the user wants to

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

梦想的初衷 提交于 2019-12-01 06:57:12
问题 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 loads the page the record it's accessing locks and then unlocks when the page is closed. Any suggestions on how to do this differently/better? I was thinking about just posting a notice on the page that they have to use a close button to close the

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

爱⌒轻易说出口 提交于 2019-11-29 06:42:31
Is there a way to call a method upon leaving a page with JSF? Not when using native JSF or PrimeFaces. Your best bet would be to hook on session expiration instead. import javax.inject.Named; import javax.enterprise.context.SessionScoped; @Named @SessionScoped public class Bean implements Serializable { @PreDestroy public void destroy() { // Your code here. } } If you happen to use the JSF utility library OmniFaces , then you can use its @ViewScoped . This will call the @PreDestroy when leaving the page referencing the view scoped bean. import javax.inject.Named; import org.omnifaces.cdi

Capturing result of window.onbeforeunload confirmation dialog

眉间皱痕 提交于 2019-11-27 23:40:23
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 it's slightly different in other browsers, but you always have some form of yes/no buttons. Presumably if they're still on the offending page after the event has been triggered they chose to stay and you could probably figure this out by watching the sequence of js. However I would like to know how to determine if they clicked "Leave this page" ? I

Capturing result of window.onbeforeunload confirmation dialog

邮差的信 提交于 2019-11-26 21:34:11
问题 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 it's slightly different in other browsers, but you always have some form of yes/no buttons. Presumably if they're still on the offending page after the event has been triggered they chose to stay and you could probably figure this out by watching