Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Alternating pop-ups

Status
Not open for further replies.

don320

Programmer
Apr 8, 2005
11
US
Does anyone know how to make a pop-up change with each new visitor. I have created a pop-up that randomly changes but my work wants it to go from lastchance.html to lastchance5.html each time a visitor enters the site.


var expDays = 7; // the number of days the cookie will last
var popup=new Array();
popup[0]=new Array("popup[1]=new Array("popup[2]=new Array("popup[3]=new Array("popup[4]=new Array("var winprops = "width=400, height=430,location=no,toolbar=no,menubar=no,scrollbars=no,resizeable=yes";
exited = 1;

if(exited){
var count = GetCookie('count');
if(count == null){
count=1;
SetCookie('count', count, exp);
// always set this value one less then the array or amount of pop-ups
var num=(Math.round(Math.random()*4));
var winpops=window.open(popup[num][0],"",winprops);
}
else{
count++;
SetCookie('count', count, exp);
This is a sample of what I was doing in JavaScript.
 
No, I am trying to see if I can create a pop-up in PHP that will allow the pop-up to alterate with each new visitor.
 

To build on my initial reply from the Javascript forum:
BabyJeffy said:
You might save a file in a special place that a PHP script can access... read the number you saved in there... increase it by one (and modulus it as needed of course)... write the file... deliver the number to the page.

In actual fact you would use this number (in PHP) to determine what url you output to the page (from an array stored server-side) and then output the appropriate information directly into your javascript on the page. This also has the benefit of "hiding" the other urls from casual readers.

If anyone wants to build on this and provide the PHP side of things... I am sure the poster would appreciate it.

Cheers,
Jeff
 
It is possible. Mostly PHP with a little JavaScript.

Your page uses JavaScript or what have you to open a new window the source of which is, say, "rotator.php" on your server.

rotator.php maintains a database of the URLs which are the content of the popups, and picks one which has been visited less often than the rest. It then uses a Location HTTP header to send the popup to the URL. It then increments the count for the URL in the database.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top