Forum Moderators: open
function readCookie(name) {
var nameEQ = name + "=";
[b]var url = location.href;[/b]
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) {
hotel = c.substring(nameEQ.length,c.length);
//alert (hotel);
[b]document.getElementById("messageBlock").innerHTML = "Welcome to " + hotel;[/b]
return hotel;
}
I want the link with the captured url to start after 'Welcome to' and before 'hotel' on line 11.
Cheers
Lee
document.getElementById("messageBlock").innerHTML = "<a href=\"" + url + "\">Welcome to " + hotel + "</a>";
And Welcome to WebmasterWorld!
I got that last bit working a treat, but I now have another problem which I have tried and tried to get working and I just cant work it out.
As you will see, ive used PHP too from what I found on the web, but if that php works to grab the url its just not either passing it over in the cookie, or the cookie reader isnt able to read it.
Here is the cookie creater code on one page:
<body onload="createCookie('hotelcookie', '<?=$rows['Nom_Hot']?>', 365, '<? $url = $_SERVER['SERVER_NAME']; $page = $_SERVER['php_SELF']; echo "http://".$url.$page; ?>')"><script type = "text/javascript">
function createCookie(name,value,days,url) {
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+url+"; path=/";
}
Here is the cookie reader code:
<body onload="readCookie('hotelcookie')"><script type = "text/javascript">
function readCookie(name) {
var nameEQ = name + "=";
var urlRead = url;
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) {
hotel = c.substring(nameEQ.length,c.length);
//alert (hotel);
document.getElementById("messageBlock").innerHTML = "On your last visit you viewed "+"<a href=\"" + urlRead + "\">" + hotel +"</a>";
return hotel;
}
}
return null; // no display if no previous visit
}
function eraseCookie(name) {
createCookie(name,"",-1);
}
</script>
Everything else works fine, I can grab the hotel name and pass it over and it displays, but when it comes to passing over the url too and putting it to the hotel name its not workio.
Can anybody help please.
Cheers
Lee
function readCookie(name,url) {
But then the hotel name appears and the url the hotel is pointing too is not it, just the home page url with undefined as the later part of the url.
The only thing that missing is the correct url being passed over to go with the hotel name thats displayed. I cant be either picking it up correct on the cookie display page, or its not pushing the url into the cookie, or more likely knowing me both!
I am trying honest.
Lee