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
    Oct 2011
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Modifying a Popup Script

    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:

    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("http://www.pccmedia.net/P25_60sec.php", "dispwin",
    "width=350,height=350,scrollbars=yes,menubar=no");
    expire=new Date(expire.getTime()+7776000000);
    document.cookie="COOKIE1=here; expires="+expire;
    }
    // --> 
    </SCRIPT>
    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....

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

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

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,908
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    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

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    New Coder
    Join Date
    Oct 2011
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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.

  • #4
    New Coder
    Join Date
    Oct 2011
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Anyone able to help with this?


  •  

    Posting Permissions

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