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
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&
Which is why my question would be "why do you want to piss off users with that **** in the first place?"