to disable popup when user clicks on browser's refresh,back and forward

Discussion in 'JavaScript' started by samcentury, Aug 11, 2006.

  1. #1
    I wan to open a popup window when user leaves d whole site or when he changes the url. I hav done it, but problem is that it displays the popup window when user clicks on browser's refresh, forward and back button and i dnt want that. Plz help me i m working on it from last morning. Below is the code

    <html>
    <head>
    <script language="javascript" type="text/javascript">
    var ex = "true";
    function PopUp(x)
    {
    if(x==2)
    {
    ex="false";
    }
    else if (x==3 && ex=="true")
    {
    OpenWindow=window.open("", "newwin", "height=250, width=250,toolbar=no,scrollbars="+scroll+",menubar=no");
    OpenWindow.document.write("<HTML><HEAD>")
    OpenWindow.document.write("<TITLE>Thanks</TITLE></HEAD>")
    OpenWindow.document.write("<BODY BGCOLOR=white>")
    OpenWindow.document.write("Thanks to visit our site")
    OpenWindow.document.write("</BODY>")
    OpenWindow.document.write("</HTML>")
    OpenWindow.document.close()
    self.name="main"
    }
    else{ex="true";}
    }

    </script>
    </head>

    <body onUnload="PopUp(3);">

    &nbsp;&nbsp;<a href="sub_cat.php?maincat_id=<?=$cat_id?>" onclick="PopUp(2)" class="link" ><?=$cat_name?></a>

    </body>
    </html>
     
    samcentury, Aug 11, 2006 IP
  2. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #2
    mad4, Aug 11, 2006 IP