Is it possible for onunload confirm to open a new url in the same window?
Posted
by Dan Peschio
on Stack Overflow
See other posts from Stack Overflow
or by Dan Peschio
Published on 2010-05-11T18:37:31Z
Indexed on
2010/05/11
18:44 UTC
Read the original article
Hit count: 415
Hi - this is my first post and I'm a JS novice, so please forgive my ignorance...
Heres my question, its in two parts:
1.) At onunload
I want an alert that asks the user if they would like to go to a related URL. The code I'm using works, but it open the URL in a new window and this can be blocked by a pop-up blocker even though the user has opted-in. Is there a way to have it open in the same window and negate the pop-up blocker?
2.) is there a way to take the onunload function out of the body tag and put it the script?
Heres the code I'm using:
<script language=javascript>
function confirmit()
{
var closeit= confirm("Before you go would you like to add your press kit to the Search Press Kits database?");
if (closeit == true)
{window.open("http://NEWURLHERE.com");}
else
{window.close();}
}
</script>
</head>
<body onunload="confirmit();">
peace
</body>
Thanks in advance,
Dan
© Stack Overflow or respective owner