View Full Version : Modifying a Popup Script

01-04-2012, 03:23 AM
I am trying to modify a popup script to popup a lightbox on page load instead of a new window. The script identifies if the user is a new visitor and displays the popup only to new visitors.

Typically, the lightbox is triggered by an a:link. I would like to trigger it using this script so that the lightbox pops up automatically for new visitors only.

Here is the popup script:

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("http://www.pccmedia.net/P25_60sec.php", "dispwin",
expire=new Date(expire.getTime()+7776000000);
document.cookie="COOKIE1=here; expires="+expire;
// -->

I want to replace the newwin=open... command with something that will trigger the lightbox.

The section of the lightbox script that receives the trigger and variables is....

Mediabox.scanPage = function() {
// $$('#mb_').each(function(hide) { hide.set('display', 'none'); });
var links = $$("a").filter(function(el) {
return el.rel && el.rel.test(/^lightbox/i);
$$(links).mediabox({/* Put custom options here */}, null, function(el) {
var rel0 = this.rel.replace(/[[]|]/gi," ");
var relsize = rel0.split(" ");
return (this == el) || ((this.rel.length > 8) && el.rel.match(relsize[1]));
window.addEvent("domready", Mediabox.scanPage);

An example of the typical HTML tag that triggers the lightbox and feeds the variables is

<a href="http://www.pccmedia.net/other/P25_60sec.mp4" rel="lightbox[set 720 405]" title="Project 25" onClick="stop1()"/>

The rel=lightbox... is the trigger for the lightbox.

The stop1() function refers to a separate script that plays background music on the website. This also needs to be included in the new visitor popup script, but is a separate issue.....

I'm not familiar enough with JS to be able to figure this out. Any help would be GREATLY appreciated.

Philip M
01-04-2012, 08:17 AM
All modern browsers block popups unless they have been specifically requested by the user. (Not automatically onload or whatever).

It is your responsibility to die() if necessary….. - PHP Manual

01-04-2012, 04:12 PM
Thank you for your input, but what I am trying to do is not actually a popup. I am trying to trigger a lightbox that already exists on the page.

Even if it does get blocked for some users, I would still like to proceed. If anyone can help I'd greatly appreciate it.

01-06-2012, 06:03 AM
Anyone able to help with this?