how to handle the red close icon in the browser and tab close. I need to do some functionality on closing of the browser. But it should not effect the refresh and also how do I differentiate the browser close icon and tab close icon.
Asked
Active
Viewed 504 times
-1
-
But I want to stop default behavior of onbeforeunload and do my own functionality... – Pradeep Challa Jul 28 '14 at 12:41
2 Answers
2
try this :
window.onbeforeunload = function(){
// your code goes here
}

Youness
- 1,468
- 1
- 9
- 19
-
I tried this. by default it is showing a pop up which is saying you want "leave this page" or "stay on this page" I dont need this pop up and i want show my own pop up in place of default. and it will work refresh also – Pradeep Challa Jul 28 '14 at 12:07
-
-
with this we can just pass the text that will shown in the default pop up other than that we cant do anything – Pradeep Challa Jul 28 '14 at 12:10
1
I don't think there is a way to catch if a tab or the windows is closed. Anyway you can try to access the onunload or the onbeforeunload event.

PForsberg
- 11
- 1
-
I tried this. by default it is showing a pop up which is saying you want "leave this page" or "stay on this page" I dont need this pop up and i want show my own pop up in place of default. and it will work refresh also – Pradeep Challa Jul 28 '14 at 12:07
-
It is not possible to edit this dialog. All you can do is add the message, as you already did. See http://msdn.microsoft.com/en-us/library/ms536907%28VS.85%29.aspx – PForsberg Jul 28 '14 at 12:16
-
thanks PForseberg is there any way to stop this event on refresh of the page – Pradeep Challa Jul 28 '14 at 12:35
-
-
If you return nothing, the dialog does not popup: window.onbeforeunload = function() { return; }; On the other hand, that does nothing else, than if you would just not call the function ... – PForsberg Jul 28 '14 at 13:43