Web Design Forum: Redirect code not working - Web Design Forum

Jump to content

WDF
WDF Premium Memberships Reseller Hosting
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Redirect code not working Rate Topic: -----

#1 User is offline   aj77 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 5
  • Joined: 28-November 08
  • Reputation: 0
  • Experience:Nothing
  • Area of Expertise:Designer

Posted 04 December 2008 - 01:35 PM

I've got a situation where I need my site to drop a cookie so that each time the user returns they're redirected to one of five new pages, in order.

I've gotten a code which works everywhere apart from Safari, and I can't see why!
I"ll give people a look at it, maybe someone can let me know what the problem is with Safari.

</head>

<body onload = "readCookie(name)">


<script type = "text/javascript">

var name = "mypage";
var value = 0;
var days = 365;  // days before cookie expires

function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days*24*60*60*1000));
var expires = "; expires = "+ date.toGMTString();
}
else var expires = "";
document.cookie = name + "="+ value + expires + "; path=/";	  // available throughout the directory
var newpage = "flash" + value + ".html";
window.location = newpage; //redirect to the new page
}

function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i = 0;i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0)==' ') value = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) value = c.substring(nameEQ.length,c.length);
}
value ++;
if (value > 5) { value = 1 }  // redirect pages are yourpage + 1,2,3,4,5
createCookie(name,value,days);
return null;
}

</script>
<div id="container">
<div id="header">
<h1>Target
</h1>
<div id="bordersplash">
  
</div>

</div>
</body>
</html>


I'd be so grateful for any tips any of you Safari guys might have!

Cheers!
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users