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="Javascript">
<!--
function setCookie()
{
document.cookie = "hl_cookie=prod_site:SportingGoods";
}
// show me
-->
</script>
IN BODY--
<body onLoad="setCookie();">
This is how I read the cookie:
IN HEAD--
<script language="Javascript">
<!--
function readCookie()
{
var hl_cookie = document.cookie;
var break_cookie = hl_cookie.split(":"
;
var site_pref = break_cookie[1];
if (site_pref == "FoodDrug"
{
location.href = " }
if (site_pref == "Industrial"
{
location.href = " }
if (site_pref == "SportingGoods"
{
location.href = " }
if (site_pref == "LawEnforcement"
{
location.href = " }
if ((site_pref != "LawEnforcement"
&& (site_pref != "FoodDrug"
&& (site_pref != "Industrial"
&& (site_pref != "SportingGoods"
)
{
location.href = " }
}
// show me-->
</script>
IN BODY--
Link to <a href="#"
onClick="readCookie(); return false;">Products</a> Page.
Here is how I set one of the four cookies:
IN HEAD--
<script language="Javascript">
<!--
function setCookie()
{
document.cookie = "hl_cookie=prod_site:SportingGoods";
}
// show me
-->
</script>
IN BODY--
<body onLoad="setCookie();">
This is how I read the cookie:
IN HEAD--
<script language="Javascript">
<!--
function readCookie()
{
var hl_cookie = document.cookie;
var break_cookie = hl_cookie.split(":"
var site_pref = break_cookie[1];
if (site_pref == "FoodDrug"
{
location.href = " }
if (site_pref == "Industrial"
{
location.href = " }
if (site_pref == "SportingGoods"
{
location.href = " }
if (site_pref == "LawEnforcement"
{
location.href = " }
if ((site_pref != "LawEnforcement"
{
location.href = " }
}
// show me-->
</script>
IN BODY--
Link to <a href="#"
onClick="readCookie(); return false;">Products</a> Page.