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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Make popup show only once using Cookies.

    We are rookies at this and have done this all on our own for the most part. Our pop up code is below. We want the popup to only show once not every time they refresh or go back to the home page. Maybe like expire in 7 days or no show until the browser is closed then reopened. We need to know how to make the code and also where do we put it? in the HTML file we put the pop up script in? deforiginal.com

    Code:
    <html>
    <head>
    
    <script>
    var delay = "0";  //############# How long before window appears (seconds)
    var winw = "400"; //############# How wide should your window be (pixels)
    var winh = "300"; //############# How tall should the window be (pixels)
    var repeat = "0";//Do you want visitor to be able to re-open window after closing?
    var ie=(document.all);
    var ns=(document.layers);
    var ns6=(document.getElementById && !ie);
    var calculate=ns? "" : "px"
    function loadElement(){
    if(!ns && !ie && !ns6) return;
      
    if(ie) popup=eval('document.all.elementDiv.style');
    else if(ns) popup=eval('document.layers["elementDiv"]');
    else if(ns6) popup=eval('document.getElementById("elementDiv").style');
    if (ie||ns6) popup.visibility="visible";
    else popup.visibility ="show";
    displayElement()
    }
    function displayElement(){
    var agent=navigator.userAgent.toLowerCase();
    if (ie){
        documentWidth = (centerElement().offsetWidth)/2+centerElement().scrollLeft-(winw/2);
        documentHeight = (centerElement().offsetHeight)/2+centerElement().scrollTop-(winh/2);
    }
    else if (ns){
        documentWidth=window.innerWidth/2+window.pageXOffset-(winw/2);
        documentHeight=window.innerHeight/2+window.pageYOffset-(winh/2);
    }
    else if (ns6){
        documentWidth=self.innerWidth/2+window.pageXOffset-(winw/2);
        documentHeight=self.innerHeight/2+window.pageYOffset-(winh/2);
    }
    popup.left = documentWidth+calculate;
    popup.top = documentHeight+calculate;
    setTimeout("displayElement()",1000);
    }
    function centerElement(){
    return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
    }
    function closeElement(){
        if (ie||ns6) { popup.display="none"; } 
        else { popup.visibility ="hide"; }
            if (repeat == 1) { location.replace; }
    }
    </script>
        
        
    
    
    </head>
    <body onLoad="setTimeout('loadElement()',delay*1000)">
    
    
    <script>
    document.write('<table cellSpacing="0" cellPadding="0" border="1" bgcolor="white" width='+winw+' height='+winh+' id="elementDiv" style="visibility:hidden; position:absolute; top:0; left:0; z-index:1; border-color:black">');
    </script>
    <tr>
        <td align="left" valign="center" bgcolor="#444835" width="100%" height="13px">
    <font color=white size=3 face=arial><b>
    <!--################ Your page title goes here  -->
    Marry Your Protection!
        
    
        
        
    
    </b></font>
    </td>
    <td width="20%" height="10px" bgcolor="#444835" align="center">
    <font color="white" size="3" face="arial"><span onclick="closeElement()" style="cursor: cell" title="Click here to close this window"><b>CL◎SE</b></span></font>
    </td></tr>
    <tr>
    <td colspan="2">
    <!--################ Your window content here goes  -->
    
    
    <font color=black size=2 face=arial><b><center>
    
    
    <a href="http://www.facebook.com/deforiginaltac"target="_blank"><img src="http://www.deforiginal.com/template/Images/popup.jpg" alt="some_text">
        
        
    </center></b></font>
    
    
    <!--################ End of window content  -->
    </td></tr></table>
    </div>
    
    
    </body>
    </html>
    Last edited by VIPStephan; 08-06-2014 at 07:36 PM. Reason: added code BB tags

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,692
    Thanks
    25
    Thanked 657 Times in 656 Posts
    What you need to know about cookies JavaScript Cookies

    Get cookie. If exists = move on. if not exist = show pop up and set cookie.
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."


  •  

    Posting Permissions

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