
Question:
I am trying to find window/tab close event in Google Chrome. In goole chrome, unload() is not working. So i used
<body onbeforeunload="return OnBeforeUnLoad ()">
javascript Code :
function OnBeforeUnLoad() {
return "Your tutorial will be finished unexpectedly";
}
It is working fine in Chrome. But it throws default pop up of chrome. I want my own pop up box.
So how can i do this ?
Answer1:You cannot. Imagine an advertiser adding code to display a popup advert when the window is closed, or a trickster adding a popup which has "OK" and "Cancel" reversed or non-functional; it's back to the old days of the internet when browsers were too trusting and users were left occasionally needing to force-quit the browser just to escape a page.
To prevent it, these days sites are allowed to display a block of text within a standard popup. You have no more control than that.
The best proof I can offer is this: go to an online email provider and close the window while uploading something, or jsfiddle and close the window after editing something, or any major site where you can edit things without an autosave. Notice that they use the browser-standard popup. If there were an alternative, one of them would have used it.