/    Sign up×
Community /Pin to ProfileBookmark

Setting a delay on this popup script

First off, this is my first post. Thank you to anyone who can help.

I have a script that works perfectly except that I need to add a delay. It creates a gateway.

I need to add a delay from the time the page opens until the time the popup occurs.

You can test it using the script below:

Add this line the head of your html doc

[CODE] <script type=”text/javascript” src=”lock.js”></script>[/CODE]

And then the script….

[CODE]/*****************************************************/
/*USER CUSTOMIZABLE FIELDS*/

/*HEADLINE*/
var blocker_headline = ‘Content Is Locked’;

/*INSTRUCTIONAL TEXT*/
var blocker_instructionalText = ‘To unlock and watch Friday 13th you MUST complete ONE of the following 3 Offers below. Once you have completed an offer, come back to this page to view the unlocked content.’;

/*FOOTER TEXT*/
var blocker_footerText = ‘This page will automatically unlock after you fill out one of the above offers.’;

/*OFFER LINKS*/
var blocker_surveryLinks = [
{text:’Link 1′, url:’http://www.yourdomain.com’},
{text:’Link 2′, url:’http://www.yourdomain.com’},
{text:’Link 3′, url:’http://www.yourdomain.com’}
]

/*END OF USER CUSTOMIZABLE FIELDS*/
/******************************************************/

var blocker_originalHtmlOverflow;
var blocker_originalBodyOverflow;

function blocker_addLoadEvent(func)
{
var oldonload = window.onload;
if (typeof window.onload != ‘function’)
{
window.onload = func;
}
else
{
window.onload = function()
{
oldonload();
func();
}
}
}

blocker_addLoadEvent(blocker_init);

function blocker_init()
{
if(blocker_getCookie(‘content_unlocked’)==’1′)
return;

blocker_originalHtmlOverflow = document.getElementsByTagName(‘body’)[0].style.overflow;
blocker_originalBodyOverflow = document.getElementsByTagName(‘html’)[0].style.overflow;

document.getElementsByTagName(‘body’)[0].style.overflow = ‘hidden’;
document.getElementsByTagName(‘html’)[0].style.overflow = ‘hidden’;

var haze = document.createElement(‘div’);
haze.id = ‘blocker_haze’;
haze.style.filter = ‘alpha(opacity=50)’;
haze.style.opacity = .5;
haze.style.height = ‘100%’;
haze.style.width = ‘100%’;
haze.style.backgroundColor = ‘#000’;
haze.style.position = ‘absolute’;
haze.style.top = ‘0px’;
haze.style.left = ‘0px’;
haze.style.zIndex = 1000000;

var centerPane = document.createElement(‘centerPane’);
centerPane.id = ‘blocker_centerPane’;
centerPane.style.width = ‘500px’;
centerPane.style.border = ‘5px solid #CCC’;
centerPane.style.width = ‘500px’;
centerPane.style.position = ‘absolute’;
centerPane.style.left = ‘50%’;
centerPane.style.marginLeft = ‘-250px’;
centerPane.style.top= ’50px’;
centerPane.style.backgroundColor = ‘#FFF’;
centerPane.style.zIndex = 1000001;
centerPane.style.backgroundImage = ‘url(http://i41.tinypic.com/2znsvti.png)’;
centerPane.style.backgroundRepeat = ‘no-repeat’;
centerPane.style.backgroundPosition = ’20px 10px’;
centerPane.style.padding = ’20px’;

var h1 = document.createElement(‘h1’);
h1.style.color = ‘#466805’;
h1.style.textAlign = ‘center’;
h1.style.fontSize = ’38px’;
h1.style.margin = ‘0 0 10px 0’;
h1.style.padding = ‘8px 0 0 15px’;
h1.style.fontFamily = ‘arial’;
h1.style.lineHeight = ’38px’;
h1.innerHTML = blocker_headline;
centerPane.appendChild(h1);

var p1 = document.createElement(‘p’);
p1.innerHTML = blocker_instructionalText;
p1.style.textAlign = ‘center’;
p1.style.padding = ’20px 0 20px 0′;
p1.style.margin = ‘0’;
p1.style.fontSize = ’18px’;
p1.style.lineHeight = ’18px’;
p1.style.color = ‘#000’;
p1.style.fontFamily = ‘arial’;
centerPane.appendChild(p1);

var ul = document.createElement(‘ul’);
ul.style.textAlign = ‘center’;
ul.style.margin = ‘0 0 10px 0’;
ul.style.padding = ‘0’;
ul.style.listStyleType = ‘none’;
for(var i = 0;i<blocker_surveryLinks.length;i++){
var li = document.createElement(‘li’);
var a = document.createElement(‘a’);
a.style.display = ‘block’;
a.style.fontSize = ’14px’;
a.style.lineHeight = ’22px’;
a.style.color = ‘Blue’;
a.style.fontFamily = ‘arial’;
a.style.textDecoration = ‘underline’;
a.target = ‘_blank’;
a.href = blocker_surveryLinks[i].url;
a.innerHTML = blocker_surveryLinks[i].text;
a.onclick = function(){
window.setTimeout(unblockContent, 45000);
}
li.appendChild(a)
ul.appendChild(li);
}

centerPane.appendChild(ul);

var p2 = document.createElement(‘p’);
p2.style.textAlign = ‘center’;
p2.innerHTML = blocker_footerText;
p2.style.padding = ’20px 0 0 0′;
p2.style.margin = ‘0’;
p2.style.color = ‘#000’;
p2.style.fontFamily = ‘arial’;
p2.style.fontSize = ’13px’;
p2.style.lineHeight = ’13px’;
centerPane.appendChild(p2);

document.getElementsByTagName(‘body’)[0].appendChild(haze);
document.getElementsByTagName(‘body’)[0].appendChild(centerPane);
}

function unblockContent(){
document.getElementsByTagName(‘body’)[0].style.overflow = blocker_originalBodyOverflow;
document.getElementsByTagName(‘html’)[0].style.overflow = blocker_originalHtmlOverflow;

document.getElementById(‘blocker_haze’).style.display = ‘none’;
document.getElementById(‘blocker_centerPane’).style.display = ‘none’;
blocker_setCookie(“content_unlocked”, 1, 1000);
}

function blocker_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 blocker_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 “”;
}[/CODE]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@astupidnameMay 20.2009 — Just at a quick 'glance-over' I would think you could just change this:
blocker_addLoadEvent(blocker_init);[/quote]
To the following:
blocker_addLoadEvent(function () { window.setTimeout(blocker_init, 3000); } );
//3000 is the delay in milliseconds, 1000 = 1 second, adjust as desired
Copy linkTweet thisAlerts:
@webhead2authorMay 20.2009 — Works perfectly!

I am a javascript newb, but if you ever need any help with PHP, let me know, as I am the Master lol.
×

Success!

Help @webhead2 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...