...

View Full Version : Pop up window with yes/cancel that redirects if yes is clicked



aformes
12-23-2007, 11:24 AM
Hello friends,

i need the code in order to make an automatic pop up window for my blog which will ask visitors if they want to visit another site or not. With yes, they will be redirected to that site and with cancel they will just stay in my blog.

Can you help me with the code please?

Thanks in advance

Philip M
12-23-2007, 11:52 AM
Presumably by "an automatic pop up window" you mean a pop-up which is triggered when the user leaves your page.

You can use onbeforeunload (not supported by all browsers) to display a pre-exit message or confirm box, but you cannot redirect the current window or open a modal dialog from the current window in the onbeforeunload event - if that was possible the internet would be unuseable.

See:-

http://www.codingforums.com/showthread.php?t=114410

Be aware that many people very much dislike this sort of thing, and do not wish to confirm that they want to move on to another page.

BTW, the time to say "thanks" is afterwards, not beforehand which gives the impression that you take other people's assistance for granted. If you find this response helpful then please use the "Thank You For This Post" button.

aformes
12-23-2007, 12:04 PM
You're right about the "thanks" Philip

Well, i don't want this pop up to be shown when someone exits my page but when someone enters.

The first code in the link you gave me is almost what i want

Here's the code :

<script type="text/javascript">
var stay=confirm("The following site contains appalling material suitable only for webmasters. Please 'ok' to enter, 'cancel' to exit immediately!")
if (!stay)
window.location="http://www.yahoo.com"
</script>


Appalling material here


This pop up redirects if cancel is clicked and stays in the page if ok is clicked.

I want the diverse thing. Redirection when ok is clicked and stay in the page when cancel is clicked.

abduraooft
12-23-2007, 12:20 PM
Remove ! from if (!stay)

aformes
12-23-2007, 12:28 PM
Oh, that worked fine.

Thank you both for your response



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum