www.webdeveloper.com
Results 1 to 3 of 3

Thread: using cookies to allow onload popup once

  1. #1
    Join Date
    Aug 2009
    Posts
    3

    using cookies to allow onload popup once

    Hi,

    I'm not sure I have come to the right bit of this forum, but here goes.

    I have implemented a window.onload function on my website using shadowbox which just simply shows a div with a background image. The onload function works perfectly everytime, but I would like it to just popup once per person viewing the site. The script for the popup is this:

    <script type="text/javascript">
    Shadowbox.init({
    // let's skip the automatic setup because we don't have any
    // properly configured link elements on the page
    skipSetup: true,
    // include the html player because we want to display some html content
    players: ["html"]
    });

    window.onload = function(){

    // open a welcome message as soon as the window loads
    Shadowbox.open({
    content: '<div id="welcome"></div>',
    player: "html",
    title: "Welcome",
    height: 350,
    width: 350
    });

    };
    </script>



    I then saw this page: http://javascript.internet.com/cooki...opup-once.html which describes how to do the cookie part, I just have no idea how to use the onlypopuponce.js with the current script on my site.

    i hope someone can help....

  2. #2
    Join Date
    Jun 2007
    Posts
    667
    Try this:
    Code:
    window.onload = function(){
    
     if( document.cookie && !/(^|\s|;)shownDiv=true(;|$)/.test( document.cookie ))
     {
       document.cookie = 'shownDiv=true';
       Shadowbox.open({ 
       content: '<div id="welcome"></div>',
       player: "html",
       title: "Welcome",
       height: 350,
       width: 350});
     }
     
    };

  3. #3
    Join Date
    Oct 2009
    Posts
    1
    Hi Sterling, I read your solution and try to apply it but it seems it doesnt' work, I have no more popup... :-(

    Here is my code:
    Code:
    <link rel="stylesheet" type="text/css" href="shadowbox/shadowbox.css">
    <script type="text/javascript" src="shadowbox/shadowbox.js"></script>
    <script type="text/javascript">
    Shadowbox.init({
        // let's skip the automatic setup because we don't have any
        // properly configured link elements on the page
        skipSetup: true,
        // include the html player because we want to display some html content
        players: ["html"]
    });
    
    window.onload = function(){
    if( document.cookie && !/(^|\s|;)shownDiv=true(;|$)/.test( document.cookie ))
     {
       document.cookie = 'shownDiv=true';
        // open a welcome message as soon as the window loads
        Shadowbox.open({
            content:    '<div id="welcome-msg">Nous vous remercions pour votre visite et nous vous informons que la boutique sera enrichie de nouveaux produits dans les prochaines semaines. <br />Bonne visite...</div>',
            player:     "html",
            title:      "Bienvenue sur la boutique en ligne des Secrets de Lily",
            height:     120,
            width:      450
        });
    }
    };
    </script>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles