Start a script after user been on a site xx minutes

Howdy, my first post here! :bounce:

I have a script that opens a layer on my site (http://www.wedinsfonsterputs.se/nojd/). The layer contains a survey from polldaddy. Now the layer and the survey is opened when the user clicks the link. I´l looking for a js script that starts the polldaddy scipt after the user has been on the site for, lets say 2 minutes. Would that be possible with js and some session cookies? Can someone point me in the correct direction?

Cheers,
JediSthlm

Thanks for the reply. Now I just need to combine them…(grrr, I´m not a javascript guy)

Something (exactly) like this:

<script src="http://www.polldaddy.com/s.js"></script>
<script>
function checkCookie()
{
pollShown=getCookie('pollShown');
if (!(pollShown!=null && pollShown!=""))
  {
    startTime();
  }
 else
 {
    alert("Already saw the poll");
 }
}

function startTime()
{
    setTimeout("PDF_launch('82EFE463C8DFC452')", 120000);
    setCookie('pollShown',1,365);
}

function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1; 
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
return "";
}
</script>
<body onload="javascript:checkCookie();">

[quote=actionAction;2340902]Something (exactly) like this:

<script src="http://www.polldaddy.com/s.js"></script>
<script>
function checkCookie()
{
pollShown=getCookie('pollShown');
if (!(pollShown!=null && pollShown!=""))
  {
    startTime();
  }
 else
 {
    alert("Already saw the poll");
 }
}

function startTime()
{
    setTimeout("PDF_launch('82EFE463C8DFC452')", 120000);
    setCookie('pollShown',1,365);
}

function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1; 
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
return "";
}
</script>
<body onload="javascript:checkCookie();">

[/quote]

Thank you, thank you, thank you, but… it does only work partly. What I noted when trying out the script is that if the user has no cookie set it shows the “popup” just like it should. If the user comes to a page, then moves to another page, the cooke seems to be set which makes the “popup” not to show. The script only works if the user comes to a page and stays on the same page for the time set in the script.

Thanks again for helping out but could you please have a look at it again, please…

/JediSthlm

From your first post, that is what you wanted to happen. My script sets a cookie to show the user the “popup” only once when they enter the site after a set number of seconds have passed. How exactly do you need this modified?

Thanks for quick reply :slight_smile:

What I’m looking for

  1. The user enters the site, does not matter what page of the site the user enters.
  2. The user reads some on first page, clicks to another and so on.
  3. After two minutes the popups shows.
  4. If the user closes the popup or fill in the survey, the popup will not show again.

If I understand the script nows

  1. The user enters the site, does not matter what page of the site the user enters.
  2. The user reads something on first page, after two minutes the popup shows.
  3. If the user before two minutes clicks to another page within the site the pop is not shown.

Cheers,
JediSthlm

No problem,

To accomplish this you would either have to:
~Open a popup window (it could be small) when a user enters the site, and have that page run the timer.
~Push the elapsed time to a cookie in the window.onunload event and check to see if a timer is alread going in the onload event of each page. (this is probably the best option.) I think the code I gave you is pretty straight forward, try and figure out how to implement this. Here is a start:


var t;//this will hold the elapsed time;
window.onunload = function()
{
    //elapsed value gets pushed to a cookie here
    setCookie("elapsed",t,365);
}

function checkCookie()
{
   pollShown=getCookie('pollShown');
   timer = getCookie('elapsed');
   if (pollShown==null && pollShown=="")
  {
     if(timer==null && timer=="")
     {
        startTime();
     }else{
        startTime(timer);
     }
  }
 else
 {
    alert("Already saw the poll");
 }
}


function startTime(timer=120000)
{
    setTimeout("PDF_launch('82EFE463C8DFC452')", timer);
    setCookie('pollShown',1,365);
}

Thanks for your support, I´ll have a look at it and see if I come up with anything nice. If get it to work I’ll post it here.

/JediSthlm