Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    May 2006
    Posts
    92
    Thanks
    1
    Thanked 0 Times in 0 Posts

    javascript popup - cookie and center?

    Hi,

    I've found plenty of references to js popup scripts that either center the popup to the screen no matter the resolution, or use a cookie to show the popup only once in x days...but I just can't seem to figure out how I could incorporate the two? If anyone has any ideas I would be very grateful!

    What I need,

    A srcipt that opens a popup in the center of the screen and places a cookie so that on revisiting the page, the popup no longer appears.

    Cheers

  • #2
    New Coder
    Join Date
    May 2006
    Posts
    92
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Come on guys please help out!

    To get things started, here's the code I'm currently using...

    COOKIE SCCRIPT
    Code:
    <SCRIPT LANGUAGE="JavaScript">
    <!--
    function GetCookie(name) {
      var arg=name+"=";
      var alen=arg.length;
      var clen=document.cookie.length;
      var i=0;
      while (i<clen) {
        var j=i+alen;
        if (document.cookie.substring(i,j)==arg)
          return "here";
        i=document.cookie.indexOf(" ",i)+1;
        if (i==0) break;
      }
      return null;
    }
    var visit=GetCookie("COOKIE1");
    if (visit==null){
       var expire=new Date();
        window.name = "thiswin";
        newwin=open("welcome.asp", "dispwin",  
        "width=360,height=288,scrollbars=no,menubar=no");
       document.cookie="COOKIE1=here; expires=Thu 01-01-2008 00:00:00 GMT;";
    }
    // -->
    </SCRIPT>
    This sets my cookie and it works great! Now I need to find out how to incorporate a center popup script to work with this...

    I found this, but am unsure how to incorporate the two as this 'center popup script' requires that the body onload event be present, and that adds the popup link which is a bad thing as its already incorporated in the code above?? i.e. both scripts call the popup, and thus dont work together.

    CENTER POPUP SCRIPT
    Code:
    <SCRIPT LANGUAGE="JavaScript">
    <!--
    function popup( filename, params, width, height, resizable, scrollbars, windowName, centered )
    {
    	if ( width == 0 ) width = screen.availWidth - 20;
    	if ( height == 0 ) height = screen.availHeight - 20;
    	if ( centered == true ) {
    		topX = (screen.availWidth/2)-(width/2);
    		topY = (screen.availHeight/2)-(height/2);
    	} else {
    		topX = 20;
    		topY = 20;
    	}
    	if ( params != "" ) params = "?" + params;
    	window.open( filename + params, windowName, "resizable=" + resizable + ",scrollbars=" + scrollbars + ",top=" + topY + ", left=" + topX + ",width=" + width + ",height=" + height);
    }
    
    PopUp = function( width, height )
    {
    	this.page = "";
    	this.params = "";
    	this.width = width;
    	this.height = height;
    	this.resizable = "yes";
    	this.scrollbars = "auto";
    	this.windowName = "win" + new Date().getMilliseconds();
    	this.centered = true;
    }
    
    PopUp.prototype.getPageLink = function()
    {
    	return this.page + (this.params != "" ? "?" + this.params : "");
    }
    </head>
    <body OnLoad="javascript:popup('welcome.asp','',360,288,'no','no','popup',true)">
    // -->
    </SCRIPT>[/
    Hope someone can help!
    Last edited by dommy; 09-05-2006 at 02:15 PM.

  • #3
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    Give this a try

    PHP Code:
    <SCRIPT LANGUAGE="JavaScript">
    <!--
    function 
    GetCookie(name) {
      var 
    arg=name+"=";
      var 
    alen=arg.length;
      var 
    clen=document.cookie.length;
      var 
    i=0;
      while (
    i<clen) {
        var 
    j=i+alen;
        if (
    document.cookie.substring(i,j)==arg)
          return 
    "here";
        
    i=document.cookie.indexOf(" ",i)+1;
        if (
    i==0) break;
      }
      return 
    null;
    }

    var 
    visit=GetCookie("COOKIE1");

    if (
    visit==null){
    var 
    expire=new Date();
    window.name "thiswin";

    winWidth=360
    winHeight
    =288

    winX 
    = (screen.availWidth-winWidth)/2;
    winY = (screen.availHeight-winHeight)/2;

    newwin=open("welcome.asp""dispwin","left="+winX+",top="+winY+",width="+winWidth+",height="+winHeight+",scrollbars=no,menubar=no");

    document.cookie="COOKIE1=here; expires=Thu 01-01-2008 00:00:00 GMT;";
    }
    // -->
    </SCRIPT> 
    The silent one.

    The most dangerous thing in the world is an idea.
    The most dangerous person in the world is the one with an idea.

  • #4
    New Coder
    Join Date
    May 2006
    Posts
    92
    Thanks
    1
    Thanked 0 Times in 0 Posts
    You da man! No really thank you for your time!

    I'll look through it and learn a thing or 2.

    Cheers


  •  

    Posting Permissions

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