PDA

View Full Version : DHTML Window widget (v1.1)



jrthor2
02-21-2008, 01:17 PM
1) Script Title: DHTML Window widget (v1.1)

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex8/dhtmlwindow/index.htm

3) Describe problem: Is there a way to have this popup only popup once for a user, instead of evertime they come back to the page?

Thanks

jscheuer1
02-21-2008, 05:14 PM
That would require a cookie. I've taken the cookie code from quirksmode.org:

http://www.quirksmode.org/js/cookies.html

and added a little helper function at the end:


function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}

function eraseCookie(name) {
createCookie(name,"",-1);
}

function doOnce(){
var doid='popper';
if(!readCookie(doid)){
Your code here
}
createCookie(doid, doid);
}
doOnce();

So you could do it like so:


var googlewin

function doOnce(){
var doid='popper';
if(!readCookie(doid)){
googlewin=dhtmlwindow.open("googlebox", "iframe", "http://google.com", "Google Web site", "width=700px,height=450px,resize=1,scrolling=1,center=1", "recal")
}
createCookie(doid, doid);
}
doOnce();