Hi. I have a page with many links to external sites on it and i want to use cookies to display the last time each link was visited next to the link. I think the script i have for setting the cookie is ok: i'm using firefox and the various cookies appear under the cookies options. However instead of displaying only the relevant date next to each link it displays the dates for all of the links. It is as if it is completely ignoring the if statement that i have placed in bold in the script below:
This is in the head:
and this is in the body
What seems to be the problem??? Thanks.
This is in the head:
Code:
<script type="text/javascript">
function setcookie(name, date) {
newdate = new Date();
day = newdate.getDate();
month = newdate.getMonth () + 1;
year = newdate.getYear ();
hours = newdate.getHours ();
minutes = newdate.getMinutes ();
seconds = newdate.getSeconds ();
date = day+"/"+month+"/"+year+""+hours+"-"+minutes+"-"+seconds;
expirydate = new Date("December 31, 2023");
cookieexpirydate = expirydate.toGMTString();
document.cookie = name + "=" + escape(date) + ";expires=" + cookieexpirydate;
<!-- location.href = name; -->
}
function readcookie (name)
{
var cookie_string = document.cookie;
var cookie_array = cookie_string.split(";");
for (i=0; i <= cookie_array.length; i++)
{
var single_cookie = cookie_array[i].split("=")
var cookiename = single_cookie[0]
var cookievalue = single_cookie[1]
if (cookiename = name) document.write ("<br>" +cookievalue)
}
}</script>
Code:
<a href="[URL unfurl="true"]http://www.ucl.ac.uk"[/URL] onClick="javascript:setcookie('[URL unfurl="true"]http://www.ucl.ac.uk',[/URL] '')">UCL</a><span class="date">
<script>readcookie('[URL unfurl="true"]http://www.ucl.ac.uk')</script>[/URL]
</span><br>
<a href="[URL unfurl="true"]http://www.phys.ucl.ac.uk"[/URL] onClick="javascript:setcookie('[URL unfurl="true"]http://www.phys.ucl.ac.uk',[/URL] '')">UCL Physics Web
Site</a><span class="date">
<script>readcookie('[URL unfurl="true"]http://www.phys.ucl.ac.uk')</script>[/URL]
</span><br>
<a href="[URL unfurl="true"]http://www.google.com"[/URL] onClick="javascript:setcookie('[URL unfurl="true"]http://www.google.com',[/URL] '')">Google.com</a><span class="date">
<script>readcookie('[URL unfurl="true"]http://www.google.com')</script>[/URL]
What seems to be the problem??? Thanks.