Results 1 to 2 of 2

Thread: DHTML Window widget (v1.1)

  1. #1
    Join Date
    Feb 2008
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default DHTML Window widget (v1.1)

    1) Script Title: DHTML Window widget (v1.1)

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...ndow/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

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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:

    Code:
    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:

    Code:
    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();
    Last edited by jscheuer1; 02-21-2008 at 05:35 PM.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •