PDA

View Full Version : Title: Interstitial Content Box "Don't show again" link



coursons
06-20-2014, 02:44 PM
1) Script Title: Interstitial Content Box (v1.1)

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex17/interstitial.htm

3) Describe problem: I would love to be able to include an option on this script to continue displaying the ad once per browser session, but include an option for a site visitor to select "Don't show me this again." Since a cookie is already being used in this script, is there any way to add a link to not show again to that particular visitor for x number of days?

vwphillips
06-21-2014, 09:04 AM
addition code in red


/////////////End of interstitialBox object declaration here ////////////////////////////////

function getCookie(Name){
var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
if (document.cookie.match(re)) //if cookie found
return document.cookie.match(re)[0].split("=")[1] //return its value
return null
}

function setCookie(name, value, days){
var expireDate = new Date()
//set "expstring" to either an explicit date (past or future)
if (typeof days!="undefined"){ //if set persistent cookie
var expstring=expireDate.setDate(expireDate.getDate()+parseInt(days))
document.cookie = name+"="+value+"; expires="+expireDate.toGMTString()+"; "+interstitialBox.cookiesetting[1]
}
else //else if this is a session only cookie setting
document.cookie = name+"="+value+"; "+interstitialBox.cookiesetting[1]
}


var stitialvars=new Object() //temporary object to reference/ shorthand certain interstitialBox properties
stitialvars.freqtype=interstitialBox.displayfrequency[0] //"chance" or "cookie"
stitialvars.cookieduration=interstitialBox.displayfrequency[1] //"session" or int (integer specifying number of days)
stitialvars.cookiename=interstitialBox.cookiesetting[0] //name of cookie to use


if (stitialvars.freqtype=="chance"){ //IF CHANCE MODE
if (Math.floor(Math.random()*interstitialBox.displayfrequency[1])==0)
interstitialBox.launch=true
}
else if (stitialvars.freqtype=="cookie" && stitialvars.cookieduration=="session"){ //IF "SESSION COOKIE" MODE
if (getCookie(stitialvars.cookiename+"_s")==null){ //if session cookie is empty
setCookie(stitialvars.cookiename+"_s", "loaded")
interstitialBox.launch=true
}
}
else if (stitialvars.freqtype=="cookie" && typeof parseInt(stitialvars.cookieduration)=="number"){ //IF "PERSISTENT COOKIE" MODE
if (getCookie(stitialvars.cookiename)==null || parseInt(getCookie(stitialvars.cookiename))!=parseInt(stitialvars.cookieduration)){ //if persistent cookie is empty or admin has changed number of days to persist from that of the stored value (meaning, reset it)
setCookie(stitialvars.cookiename, stitialvars.cookieduration, stitialvars.cookieduration)
interstitialBox.launch=true
}
}

if (getCookie(stitialvars.cookiename)=='never'){
setCookie(stitialvars.cookiename, "never",1000);
interstitialBox.launch=false;
}


if (interstitialBox.launch)
interstitialBox.initialize()


to control


<input type="button" name="" value="Never Show" onclick="setCookie(stitialvars.cookiename, 'never',1000);" />
<input type="button" name="" value="Cancel Never Show" onclick="setCookie(stitialvars.cookiename, 'never',-1);" />


or to change the interstitial box



//3) HTML for the header bar portion of the interstitial box
defineheader: '<div class="headerbar"><a href="#" onClick="javascript:interstitialBox.closeit(); return false"><img src="http://www.vicsjavascripts.org/StdImages/1.gif" style="border: 0;width:50px;" title="Close Box"/></a><input type="button" name="" value="Never Show" onclick="setCookie(stitialvars.cookiename, \'never\',1000);" /></div>',

coursons
06-24-2014, 02:32 PM
Thank you so much! This is fantastic! I just have a couple of simple follow up questions.

1. In the js file, does the "1000" referenced in the 'never,1000' refer to how many days the cookie will prevent the ad from showing again?
2. Is there a way I can make the "Never Show" box also close the ad when clicked?

vwphillips
06-25-2014, 08:29 AM
1. In the js file, does the "1000" referenced in the 'never,1000' refer to how many days the cookie will prevent the ad from showing again?

YES


2. Is there a way I can make the "Never Show" box also close the ad when clicked?


defineheader: '<div class="headerbar"><a href="#" onClick="javascript:interstitialBox.closeit(); return false"><img src="http://www.vicsjavascripts.org/StdImages/1.gif" style="border: 0;width:50px;" title="Close Box"/></a><input type="button" name="" value="Never Show" onclick="setCookie(stitialvars.cookiename, \'never\',1000);interstitialBox.closeit();" /></div>',


or in this part of the script


if (getCookie(stitialvars.cookiename)=='never'){
setCookie(stitialvars.cookiename, "never",1000);
interstitialBox.closeit();
interstitialBox.launch=false;
}