I want to open popup window when browser closed or closed tabs.
Asked
Active
Viewed 2.7k times
3
-
you can use window.onUnLoad function of javascript – Dr. Rajesh Rolen Nov 01 '10 at 09:59
-
when page refresh it's also called – Pradeep Singh Nov 01 '10 at 10:18
-
try window.onclose(); https://developer.mozilla.org/en/DOM/window.onclose – Dr. Rajesh Rolen Nov 01 '10 at 10:31
-
Please don't do this, though. It's one of the easiest ways to annoy your users. – seagull Feb 04 '16 at 09:31
1 Answers
3
window.onUnLoad= function (evt) {
//your code goes here
window.open("yourpage/some link");
}
EDIT NOTE: Now it will be called on onUnload event of browser. Try now
Try window.onclose event:
https://developer.mozilla.org/en/DOM/window.onclose
How to capture the browser window close event?
References:
http://dotnetacademy.blogspot.com/2010/09/call-function-in-javascript-before.html
On below like you can find all events with example of window for javascript:
http://www.java2s.com/Tutorial/JavaScript/0380__Window/windowonUnLoad.htm

Mohammed Abrar Ahmed
- 2,290
- 3
- 15
- 33

Dr. Rajesh Rolen
- 14,029
- 41
- 106
- 178
-
-
@Pradeep: actually i created this function to ask user before closing browser that are u really want to close browser. let me modify it. – Dr. Rajesh Rolen Nov 01 '10 at 09:55