Announcement

Collapse
No announcement yet.

Show div on first page view only

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Show div on first page view only

    I would like to display a div on the first page view made by the visitor.

    The aim is to show a cookie directive message that shows on the home page on first view but doesn't keep reappearing each time they return to the home page.

    This code works in a normal php page:
    Code:
    <?php
    if(isset($_COOKIE['div'])){
      echo "<div>I can tell you've been here before</div>";
    } else {
      setcookie('div', true, 3600 * 24 + time()); //hold for 1 day
      echo "<div>Its your first time being here</div>";
    }
    ?>
    See it here: http://www.graphicz.eu.com/kook.php

    However, if I put the same code in the outer layout of my Sellerdeck store thus:
    Code:
    <actinic:block php="true" >
    if(isset($_COOKIE['div'])){
      echo "<div>I can tell you've been here before</div>";
    } else {
      setcookie('div', true, 5184000 + time()); //hold fo 2 months
      echo "<div>Its your first time being here</div>";
    }
    </actinic:block>
    <actinic:block php="true" >
    It doesn't work - see it here: http://www.graphicz.eu.com/minimal/

    The expression 'Its your first time being here' top left doesn't change as it does in the plain php page above.

    Please can anyone point me in the right direction?

    Thank you.
    Jonathan Chappell
    Website Designer
    SellerDeck Website Designer
    Actinic to SellerDeck upgrades
    Graphicz Limited - www.graphicz.co.uk

    #2
    The difference between the two is that the first is a php page that is executed on the server, the second is in SellerDeck and is executed in SellerDeck at the time the pages are produced before uploading.

    I think you may have to look at doing this in javascript so that it only executes in the browser. There are quite a few ad ins to do this around the web.

    Comment


      #3
      Your test site uses index.html, should that be index.php? or have you edited the htaccess to allow php to run?. If you changed it to php and used the first piece of php layout code and not block code you might be in business.
      Peblaco

      Comment


        #4
        One always misses the obvious!

        Thank you!
        Jonathan Chappell
        Website Designer
        SellerDeck Website Designer
        Actinic to SellerDeck upgrades
        Graphicz Limited - www.graphicz.co.uk

        Comment


          #5
          This works:

          http://www.graphicz.eu.com/kook2.html

          Code:
          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
          <html xmlns="http://www.w3.org/1999/xhtml">
          <head>
          <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
          <title>Untitled Document</title>
          
          <style type="text/css">
          <!--
          span.byebye {cursor:pointer;color: #000066; }
          span:hover.byebye {color: #0000CC; text-decoration:underline; }
          .style1 {
          	color: #0000FF;
          	font-family: "Trebuchet MS";
          }
          .style2 {
          	color: #6666CC;
          	font-family: "Trebuchet MS";
          }
          #hello {
          	text-align: center;
          	width: 200px;
          	height: 100px;
          	margin: 100px auto 0 auto;
          	border: 1px solid #000033;
          	background-color: #FFCCFF;
          	}
          -->
          </style>
          <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
              <script type="text/javascript">
                  $(function () {
                      $(".byebye").click(function () {
                          $("#hello").remove();
                      });
                  });
              </script>
          <script type="text/javascript">
          if( !window.localStorage) {
              // no localStorage (old browser) 
              // or just do nothing 
          }
          else {
              if( !window.localStorage.isReturningVisitor) {
          		document.write("<div id=\"hello\">");
          		document.write("  <h2 class=\"style1\">Hello<\/h2>");
          		document.write("  <p class=\"style2\">This is your first time here<\/p>");
          		document.write("<span class=\"byebye\">OK by me - close the div<\/span>");
          		document.write("<\/div>");
          		
                  window.localStorage.isReturningVisitor = true;
              }
          }
          </script>
          </head>
          
          <body>
          
          
          
          </body>
          </html>
          And in Sellerdeck: http://www.graphicz.eu.com/minimal/index.html

          I got this concept from Stack Overflow but regret lost the reference to the page.
          Jonathan Chappell
          Website Designer
          SellerDeck Website Designer
          Actinic to SellerDeck upgrades
          Graphicz Limited - www.graphicz.co.uk

          Comment

          Working...
          X