How to Open a new window when a visitor FIRST enters the website?

Discussion in 'HTML & Website Design' started by hellguy, Apr 9, 2014.

  1. #1
    Hello!
    I`m trying to create in wordpres a new window for members that enters on website and to set a cookie so the new window will never show again.
    I tried with these two scripts:
    <body onclick="<?php if(!isset($_COOKIE['visited'])){echo"window.open('http://google.com', '_blank')"; setcookie("visited", "1", time()+3600*24*365);} ?>">
    PHP:
    And
    $(document).ready(function(){
        if ($.cookie('visited') != '1') {
    
            //The previous script goes ere
    
            // Set cookie and duration
            $.cookie('visited', '1', { expires: 60});
        }
    
    });
    Code (markup):
    but for both of them it opens the window every time i click on the website.
    i inserted the code at the begining of header.php and in footer.php file.

    Are the scripts wrong? or i insert them in the wrong place?

    Thank you in advance :)
     
    Solved! View solution.
    hellguy, Apr 9, 2014 IP
  2. #2
    You cannot test a PHP variable in the browser. PHP runs on the server. A better solution is to use PHP server side to re-direct to the conditional page. You can test and set the cookie from the server. Using a popup will mean that it does not work correctly for the 60% of internet user who use a popup blocker. You will also have an issue with user that block cookies unless you let them know they need to enable cookies to use the site.

    Cd&
     
    COBOLdinosaur, Apr 9, 2014 IP
  3. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #3
    Which is why my question would be "why do you want to piss off users with that **** in the first place?"
     
    deathshadow, Apr 9, 2014 IP
    kk5st likes this.