Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-04-2006, 02:18 PM   PM User | #1
dommy
New Coder

 
Join Date: May 2006
Posts: 92
Thanks: 1
Thanked 0 Times in 0 Posts
dommy is an unknown quantity at this point
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
dommy is offline   Reply With Quote
Old 09-05-2006, 02:13 PM   PM User | #2
dommy
New Coder

 
Join Date: May 2006
Posts: 92
Thanks: 1
Thanked 0 Times in 0 Posts
dommy is an unknown quantity at this point
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..
dommy is offline   Reply With Quote
Old 09-05-2006, 04:54 PM   PM User | #3
Mr J
Senior Coder

 
Join Date: Aug 2002
Location: UK
Posts: 2,789
Thanks: 2
Thanked 14 Times in 14 Posts
Mr J is on a distinguished road
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.
Mr J is offline   Reply With Quote
Old 09-05-2006, 11:23 PM   PM User | #4
dommy
New Coder

 
Join Date: May 2006
Posts: 92
Thanks: 1
Thanked 0 Times in 0 Posts
dommy is an unknown quantity at this point
You da man! No really thank you for your time!

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

Cheers
dommy is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:00 PM.


Advertisement
Log in to turn off these ads.