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 9 of 9
  1. #1
    New to the CF scene
    Join Date
    May 2003
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry one time popup using cookies

    Hi -

    I have used two scripts that I found on the
    web - both proport to only load a popup once
    per session - one is from pc magazine April
    issue, another I will list here - they use
    cookies, here is my dir structure on my web
    site

    root
    dir1
    dir2
    dir3

    .js is in root, pages in dir1 and dir2 and
    dir3 call it, popup comes up once per
    dir hit, not once per site hit!

    My site

    informationhighwaytohell.com

    go to travelogue, then move around, you see
    popup is loading more than once - what gives?
    The js is in a .js file that gets called
    by every page

    http://javascriptkit.com/popwin/index.shtml

    <script>

    //Popup Window Script
    //By JavaScript Kit (http://javascriptkit.com)
    //JavaScript tutorials and over 400+ free scripts

    function openpopup(){
    var popurl="http://fullwebaddresshere"
    winpops=window.open(popurl,"","width=400,height=338,")
    }

    function get_cookie(Name) {
    var search = Name + "="
    var returnvalue = "";
    if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    if (offset != -1) { // if cookie exists
    offset += search.length
    // set index of beginning of value
    end = document.cookie.indexOf(";", offset);
    // set index of end of cookie value
    if (end == -1)
    end = document.cookie.length;
    returnvalue=unescape(document.cookie.substring(offset, end))
    }
    }
    return returnvalue;
    }

    function loadornot(){
    if (get_cookie('poppedup')==''){
    openpopup()
    document.cookie="poppedup=yes"
    }
    }

    loadornot()
    </script>

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    Try this one



    <SCRIPT language=JavaScript>
    <!--
    var expDays = 1; // number of days the cookie should last

    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 getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break;
    }
    return null;
    }

    function SetCookie (name, value,expires) {
    var argv = SetCookie.arguments;
    var argc = SetCookie.arguments.length;
    var expires = (argc > 2) ? argv[2] : null;
    var path = (argc > 3) ? argv[3] : null;
    var domain = (argc > 4) ? argv[4] : null;
    var secure = (argc > 5) ? argv[5] : false;
    document.cookie = name + "=" + escape (value) +
    ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
    ((path == null) ? "" : ("; path=" + path)) +
    ((domain == null) ? "" : ("; domain=" + domain)) +
    ((secure == true) ? "; secure" : "");
    }

    function DeleteCookie (name) {
    var exp = new Date();
    exp.setTime (exp.getTime() - 1);
    var cval = GetCookie (name);
    document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
    }
    var exp = new Date();
    exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

    function getCookieVal(offset) {
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1)
    endstr = document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
    }

    function checkCount() {
    var count = GetCookie('poponce');
    if (count == null) {
    count++;
    SetCookie('poponce', count, exp);

    // Action to take
    dothis()
    }
    }

    function dothis(){
    var windowprops = "left=50,top=150,width=300,height=200,location=no,toolbar=no,menubar=no,scrollbars=no"; window.open("yourpage.htm", "", windowprops); // Use to load a page
    }
    // -->
    </SCRIPT>

    Insert the onLoad event handler into your BODY tag.

    <BODY OnLoad="checkCount()">




  • #3
    New Coder
    Join Date
    May 2003
    Location
    Japan
    Posts
    63
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question One time pop up

    Do either of these codea allow me to use the information in the popup in the middle of a text? I wish to use a persons name many times on many pages.

    eg: " As you know we here at xxxxx.com believe this is the best idea for you. POP UP NAME, if you should agree then please e-mail us. POP UP NAME, please remember to include your reference number.
    Regards
    Staff"

    Do you see what I mean?

    Jason Rafton
    Forever Trying!!
    Always Learning!!

  • #4
    New Coder
    Join Date
    Jul 2009
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Mr J View Post
    Try this one



    <SCRIPT language=JavaScript>
    <!--
    var expDays = 1; // number of days the cookie should last

    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 getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break;
    }
    return null;
    }

    function SetCookie (name, value,expires) {
    var argv = SetCookie.arguments;
    var argc = SetCookie.arguments.length;
    var expires = (argc > 2) ? argv[2] : null;
    var path = (argc > 3) ? argv[3] : null;
    var domain = (argc > 4) ? argv[4] : null;
    var secure = (argc > 5) ? argv[5] : false;
    document.cookie = name + "=" + escape (value) +
    ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
    ((path == null) ? "" : ("; path=" + path)) +
    ((domain == null) ? "" : ("; domain=" + domain)) +
    ((secure == true) ? "; secure" : "");
    }

    function DeleteCookie (name) {
    var exp = new Date();
    exp.setTime (exp.getTime() - 1);
    var cval = GetCookie (name);
    document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
    }
    var exp = new Date();
    exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

    function getCookieVal(offset) {
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1)
    endstr = document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
    }

    function checkCount() {
    var count = GetCookie('poponce');
    if (count == null) {
    count++;
    SetCookie('poponce', count, exp);

    // Action to take
    dothis()
    }
    }

    function dothis(){
    var windowprops = "left=50,top=150,width=300,height=200,location=no,toolbar=no,menubar=no,scrollbars=no"; window.open("yourpage.htm", "", windowprops); // Use to load a page
    }
    // -->
    </SCRIPT>

    Insert the onLoad event handler into your BODY tag.

    <BODY OnLoad="checkCount()">




    I tried it.. it works in Firefox but not IE.8.. why is this?

  • #5
    New Coder
    Join Date
    Aug 2009
    Posts
    84
    Thanks
    1
    Thanked 7 Times in 7 Posts
    it's because IE is not standards-compliant, and therefore IE fails epically.

  • #6
    New Coder
    Join Date
    Jul 2009
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by orca8767 View Post
    it's because IE is not standards-compliant, and therefore IE fails epically.
    so how do i remedy this?

    i just need a simple popup php script or html code so i can get this working for my boss

  • #7
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,149
    Thanks
    203
    Thanked 2,547 Times in 2,525 Posts
    Most modern browsers block unrequested pop-ups.

    You may do better with something like this:-

    Code:
    <div id = "div1">Hi.  This will appear if the cookie is not set.</div.>
    
    <script type = "text/javascript">
    
    function getCookie() {
    if ( document.cookie.indexOf("mycookie") < 0 ) {
    //if not found show the div
    document.getElementById("div1").innerHTML = "Hello! This will appear only once per session."
    document.cookie = "mycookie = yes"; // set cookie for next time...without expire so session only
    } 
    }
    
    getCookie();
    
    </script>

  • #8
    New Coder
    Join Date
    Jul 2009
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Philip M View Post
    Most modern browsers block unrequested pop-ups.

    You may do better with something like this:-

    Code:
    <div id = "div1">Hi.  This will appear if the cookie is not set.</div.>
    
    <script type = "text/javascript">
    
    function getCookie() {
    if ( document.cookie.indexOf("mycookie") < 0 ) {
    //if not found show the div
    document.getElementById("div1").innerHTML = "Hello! This will appear only once per session."
    document.cookie = "mycookie = yes"; // set cookie for next time...without expire so session only
    } 
    }
    
    getCookie();
    
    </script>

    which code do i replace? the whole script? help me please

  • #9
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,149
    Thanks
    203
    Thanked 2,547 Times in 2,525 Posts
    Quote Originally Posted by groogruxking40 View Post
    which code do i replace? the whole script? help me please
    Yes, replace the existing script with this one.


  •  

    Posting Permissions

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