How to automatically open a new tab when visitors access website

Mr Grey

Newbie
Joined
Jul 15, 2013
Messages
28
Reaction score
2
Hi there,

I'd like to know if one of you guys could take some time to explain to me how to automatically open a new tab when visitors access my website for the first time (without them clicking any link).

This should only happen on the first visited page (on every page it would be too much of a pain in the ass for the readers).

Any idea how I could do that ? So far I've been thinking about something like that:

Code:
$("#afflink").click(function() {
       setTimeout(function() {
            window.open(
               'url',   '_blank' 
        );
     
      }, 2000); // 2000 for 2 seconds, 1000 for 1 second etc
});

Problem is this will be active all the time not only on the first visited page so far too agressive for users.

Thanks for your help !
 
You'll probably have to set some kind of cookie to recognise if they've visited the site before. That way if they have no cookie then open the tab. If they have a cookie, dont open the tab. I'm not that tech savy with java script so I'm not 100% how to do it. But search around for that? I'm sure it'd be easy to implement
 
I found a simple JS-script that sets a cookie, when someone is new. Maybe just increase the expire time. Hope it helps, Cheers

Code:
if (document.cookie.indexOf("visited") >= 0) {
  // a returning customer
  // do nothing or do something else :-)
}
else {
  // set new cookie
  expiry = new Date();
  expiry.setTime(date.getTime()+(10*60*1000)); // Ten minutes


  // Date()'s toGMTSting() method will format the date correctly for a cookie
  document.cookie = "visited=yes; expires=" + expiry.toGMTString();
  
  // your open link function here
}
 
Thanks guys ! I'll try to figure something out based on your info. Hope this will work :D
 
Back
Top