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
    Jan 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Please Help with Java Script Code That Triggers Open In New Browser/Window

    Hello all,I have a website and I would like a pop-up window to promote a new website venture I have. I would like for the new website to open in a completely new window/browser when my members simply click on the index page (No link or Buttons).The code below does most of what I ask lol,but it..

    1.Only opens in a new tab (in same browser) while I would like for it to open in a completely new browser "full page" menu bar scroll tab and all.
    plus
    2.It seems to open each and every time the page is clicked,which will be annoying to my members.I would only like for it to open 1 time per visitor every 24 hours or whenever cookies are cleared.

    Code:
    <html>
    
    <head>
    <script type="text/javascript">
    function click_on()
    {
       window.open("URL HERE", "_blank");
    }
    </script>
    </head>
    
    <body onclick="click_on()">   
    
    </body>
    
    </html>
    I am no expert at this,and my knowledge is very limited,so excuse me if this is a simple situation.Any help would be greatly appreciated.

    Thanks,
    Roco

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,310
    Thanks
    203
    Thanked 2,563 Times in 2,541 Posts
    "_blank" causes the page to open in a new window.

    To allow the page to be opened only once per 24 hours:-

    Code:
    <html>
    <head>
    <title>Cookie: permit page to show once a day</title>
    
    <script type="text/javascript">
    var show = false;
    function click_on() {
    if (show) {  // only if the cookie was not found
    window.open("http://www.google.com", "_blank");
    }
    }
    </script>
    
    <script type="text/javascript">
    
    function checkBanner() {
    show = false;
    if ( document.cookie.indexOf("zy181gg$xx") < 0 )    {   // cookie not found
    show = true;
    click_on();  // for testing
    // if cookie not found set it
    var expDate = new Date();
    expDate.setTime(expDate.getTime()+24*60*60*1000); // one day ahead
    document.cookie = "gyz$xx=zy181gg$xx; expires=" + expDate.toGMTString() + "path=/";
    }
    }
    
    </script>
    
    </head>
    
    <body onload = "checkBanner()">
    <div id = "container" onclick = "alert('User Clicked'); click_on()">
    THE WEBPAGE IN HERE
    </div>
    
    
    </body>
    </html>

    "In the beginner's mind there are many possibilities, but in the expert's mind there are few” - Shunryu Suzuki (Japanese Zen priest, ?-1971)

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Posting Permissions

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