Results 1 to 2 of 2

Thread: Need help with popup onunload event

  1. #1
    Join Date
    Jun 2005
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Need help with popup onunload event

    Hi,

    I saw lot of good posts on this forum and i hope someone will also help me out in my prob here is what i want to do

    When a user opens a page and try to close the page or got other page without clicking on a link then a popup should appear and page will not close until the popup is closed.

    Please please i really need solution.

    Thanx in advance

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    It depends upon what you mean by a pop-up. The simplest is the alert box. Using that to fulfill your requirements as I understand them could be done something like this:
    Code:
    <html>
    <head>
    <title>Test Condition - Demo</title>
    <script type="text/javascript">
    var go
    function checker(){
    if (go!=='OK'){
    alert('Please Click Required Link')
    location.href=unescape(location.href)
    }
    }
    </script>
    </head>
    <body onunload="checker()">
    </body>
    <noscript><p>Javascript required to go forward from here, use your browser's 'Back' button if you do not wish to proceed.</p></noscript>
    Required Link: <a href="#" onclick="go='OK';return false;">Click Here to Certify that You are Willing to View more content on this site</a><br>
    <a href="#" onclick="location.href='cool.htm';return false;">Optional link to Cool Stuff</a><br>
    <script type="text/javascript">
    document.write('<a href="javascript:history.go(-1)" onclick="go=\'OK\';return true;">Click here to Go Back, you chicken?</a>');
    </script>
    </html>
    There are many other ways.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

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