PDA

View Full Version : Using Cookies To Show Different Content



johnathanr
01-17-2011, 08:45 PM
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:


{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

Oziam
01-18-2011, 01:40 AM
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:


{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.