Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Dec 2007
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Pop up window with yes/cancel that redirects if yes is clicked

    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

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,302
    Thanks
    203
    Thanked 2,562 Times in 2,540 Posts
    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.
    Last edited by Philip M; 12-23-2007 at 12:54 PM.

  • Users who have thanked Philip M for this post:

    aformes (12-23-2007)

  • #3
    New to the CF scene
    Join Date
    Dec 2007
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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.

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    Remove ! from if (!stay)
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    aformes (12-23-2007)

  • #5
    New to the CF scene
    Join Date
    Dec 2007
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Oh, that worked fine.

    Thank you both for your response


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •