I want to learn window.close() and window.stop() ,
so i tried it in a simple HTML page. But there is a problem, i'am using my function in a tag. and window.stop() does not stop the operation. I want to stop the redirection if confirm dialog not true. How can i fix this problem?
<title> My page </title>
<a href = "http://www.google.com" onclick="whereAreYouGoing()">Go</a>
var exit = confirm("Are You Want to Sure to Leave?");
window.onbeforeunload = whereAreYouGoing;
onbeforeunload always runs before a window is closed; so, if you wire the function to it, it'll call the function before closing the window.
Although that will display the dialog to the user before closing the window, all browsers gives the user the opportunity to override the function; this means that if the user wants to close the window, the browser will close the window, even if your function tries to prevent that from happening.
Hope this helps.