Results 1 to 6 of 6

Thread: Display hidden layer only once per visit

  1. #1
    Join Date
    Jun 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Display hidden layer only once per visit

    I want to call a pop up registration form from my home page. However, I only want it to be called just once so that I don't annoy visitors. How do I best achieve this?
    I want to use a hidden layer for the pop up so my question is can I use DHTML in the middle of a conditional javascript if statement. i.e. before the end of the curly brackets so that it is a result of the conditional statement? Do I have to enclose the DHTML in anyway; as you can see I am pretty new to javascript/DHTML?
    I have tried to use cookies to flag a second visit to the home page; am I getting warm? Can anybody help me with some suggestions or point me at some code I can look at?
    In anticipation of assistance
    Thanks

  2. #2
    Join Date
    Mar 2006
    Location
    Cleveland, Ohio
    Posts
    574
    Thanks
    6
    Thanked 5 Times in 5 Posts

    Default

    Yeah, you're getting warm. Try using PHP sessions. Once the form is called the first time, create a PHP session. Then, on the index, check if that session exists. If it doesn't, meaning it's their first visit to the index page, show the popup. If it does exist, don't show the popup. If you need specific code, let me know.
    Thou com'st in such a questionable shape
    Hamlet, Act 1, Scene 4

  3. #3
    Join Date
    May 2007
    Location
    USA
    Posts
    373
    Thanks
    2
    Thanked 4 Times in 4 Posts

    Default

    Without PHP you could try using cookies. Whenever a page in within your domain loads, have a pagesOpened count go up and reset a cookie with the new value. If the value is zero (when the first page loads) then the counter would increment and the pop-up could display. Then when each window onunloads decremenet the count in the cookie. I think this would work.

  4. #4
    Join Date
    Dec 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    People are always telling me that more sinple, is better, so;

    why not simply initiate your popup on your index.html page, then, after a user selects another page (or whatever), always/only point them 'back' to an identical index page (index2.html), without the popup on it ..

  5. #5
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    if you're leaning toward javascript, here you go:

    css:
    Code:
    .unviewed {
    visibility:visible
    }
    
    .viewed {
    visibility:hidden
    }
    Code:
    function setViewed() {
    	
    		var date = new Date();
    		date.setTime(date.getTime()+(days*24*60*60*1000));
    		var expires="+date.toGMTString();
                              document.cookie = "seen=yes;"+expires+"; path=/";
    }
    
    function returncookie() {
    	var name = "seen";
    	var ca = document.cookie.split(';');
    	for(var i=0;i < ca.length;i++) {
    		var c = ca[i];
    		while (c.charAt(0)==' ') c = c.substring(1,c.length);
    		if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
    	}
    	return null;
    }
    function checkViewed {
    var viewed = returncookie();
    if (viewed != null) {
    document.getelementbyid('layer').class = "viewed";
    } else {
    document.getelementbyid('layer').class = "unviewed";
    setViewed();
    }
    and for the body tag:
    Code:
    <body onLoad="checkViewed()">
    and set your layer's id to "layer"
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@ /\/\@|{
    There are 10 kinds of people in the world, those that understand binary and those that don't.

  6. #6
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    for php:
    php:
    Code:
    <?php
    function setViewed() {
    setcookie("viewed", "yes", time()+99999);
    }
    
    if (isset($_COOKIE[viewed])) {
    } else {
    echo "layer code";
    setViewed();
    }
    ?>
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@ /\/\@|{
    There are 10 kinds of people in the world, those that understand binary and those that don't.

Bookmarks

Posting Permissions

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