views:

303

answers:

1

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

A: 
  • If there would be a way to bypass the pop-up blocker it would be a bad pop-up blocker.
  • As far as I know you need a popup, because when onUnload is executed, the original window might be already closed.
  • Yes, you can move it to the script part:

    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();} } window.onunload = confirmit
rami
WOW! that was fast - both work... now about that pop-up blocker...
Dan Peschio
Hey - if I used the beforeonunload command would that allow me to load into the same window and not need a pop-up?
Dan Peschio
I don't know but I have a tip for you: Try it! Do it! You'll see, whether it works :-)
rami
AFAIK beforeonunload isn't supported by all browsers! But try it ;-)
rami
so on the script you gave me, I would change window.onunload = confirmit towindow.onbeforeunload = confirmit
Dan Peschio