Results 1 to 2 of 2

Thread: Using Cookies To Show Different Content

  1. #1
    Join Date
    Jan 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Using Cookies To Show Different Content

    Hi everyone,
    I'm a complete novice to javascript and have been looking around for a few days now trying to figure this one out. If you have any advice or ideas, I'd GREATLY appreciate it!

    Here is what I'm trying to do. I run a review site with multiple cities.
    For each city page, I want to display different banners. When someone comes to my site, they select the city they are from and a cookie is set.
    The cookie is called "transfer_page" and the values are "LA" "NY" "London" etc.

    I have different banner campaigns for each city.
    So, once a visitor has selected their page (and the cookie has been set), I want them to only see the banners that apply to their city.

    Here is the cody I'm using right now. I'm using smarty templates as well, if that helps at all. (so I'm using the {literal} tag as well)

    Here is what I'm come up with so far:
    Code:
    {literal}
    <script type="text/javascript">		
    function checkCookie()
    {
    var city=getCookie('transfer_page');
    if (city!=null && city!="LA")
      {
     	document.write('{$ads->getAdCode(1)');
      }
    if (city!=null && city!="London")
      {
     	document.write('{$ads->getAdCode(2)');
      }
    else
      {
     	document.write('{$ads->getAdCode(3)');  
      }
    }
    </script>
    {/literal}
    Thank you again for any insight you may be able to provide. Please go easy on me, I'm sure the above code is completely wrong! ;-)

    Thanks again,
    John

  2. #2
    Join Date
    Jan 2011
    Location
    QLD, Australia
    Posts
    23
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default

    Quote Originally Posted by johnathanr View Post
    Hi everyone,
    I'm a complete novice to javascript and have been looking around for a few days now trying to figure this one out. If you have any advice or ideas, I'd GREATLY appreciate it!

    Here is what I'm trying to do. I run a review site with multiple cities.
    For each city page, I want to display different banners. When someone comes to my site, they select the city they are from and a cookie is set.
    The cookie is called "transfer_page" and the values are "LA" "NY" "London" etc.

    I have different banner campaigns for each city.
    So, once a visitor has selected their page (and the cookie has been set), I want them to only see the banners that apply to their city.

    Here is the cody I'm using right now. I'm using smarty templates as well, if that helps at all. (so I'm using the {literal} tag as well)

    Here is what I'm come up with so far:
    Code:
    {literal}
    <script type="text/javascript">		
    function checkCookie()
    {
    var city=getCookie('transfer_page');
    if (city!=null && city!="LA")
      {
     	document.write('{$ads->getAdCode(1)');
      }
    if (city!=null && city!="London")
      {
     	document.write('{$ads->getAdCode(2)');
      }
    else
      {
     	document.write('{$ads->getAdCode(3)');  
      }
    }
    </script>
    {/literal}
    Thank you again for any insight you may be able to provide. Please go easy on me, I'm sure the above code is completely wrong! ;-)

    Thanks again,
    John
    What is $ads->getAdCode(3) ? Is this PHP code??

    if so I am pretty sure you cannot write php code
    to the page, especially in a template, it will be shown as a literal string.

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
  •