Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem reading cookie (in most browsers)

Status
Not open for further replies.

sarak

Programmer
May 3, 2001
25
US
I am very new to JavaScript and have tried to create a temporary cookie that affects where clicking on a link will take a visitor. For example, a link called "Products" will take a visitor to the Sporting Goods products page or Food & Drug products page or back to the main page, depending on the data (or lack of) returned in the cookie. I can only get my cookie to work on IE for Mac (running 9.1)... no luck on any other browsers or operating systems. Any advice would be GREATLY appreciated! Thanks!

Here is how I set one of the four cookies:

IN HEAD--
<script language=&quot;Javascript&quot;>
<!--
function setCookie()
{
document.cookie = &quot;hl_cookie=prod_site:SportingGoods&quot;;
}
// show me
-->
</script>

IN BODY--
<body onLoad=&quot;setCookie();&quot;>


This is how I read the cookie:

IN HEAD--
<script language=&quot;Javascript&quot;>
<!--

function readCookie()
{
var hl_cookie = document.cookie;

var break_cookie = hl_cookie.split(&quot;:&quot;);

var site_pref = break_cookie[1];

if (site_pref == &quot;FoodDrug&quot;)
{
location.href = &quot; }

if (site_pref == &quot;Industrial&quot;)
{
location.href = &quot; }

if (site_pref == &quot;SportingGoods&quot;)
{
location.href = &quot; }

if (site_pref == &quot;LawEnforcement&quot;)
{
location.href = &quot; }

if ((site_pref != &quot;LawEnforcement&quot;) && (site_pref != &quot;FoodDrug&quot;) && (site_pref != &quot;Industrial&quot;) && (site_pref != &quot;SportingGoods&quot;))
{
location.href = &quot; }
}
// show me-->
</script>

IN BODY--

Link to <a href=&quot;#&quot;
onClick=&quot;readCookie(); return false;&quot;>Products</a> Page.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top