I run next code and I miss somthing, for me it seem OK :
window.onload = TitleFieldInit;
function TitleFieldInit() {
var str = document.cookie.split("=")[1];
var space = str.split("=")[1];
space = space.split(";")[0];
alert(space);
// while( space.indexOf('%20' )+1) space = space.replace(/%20/,' ');
if (document.cookie != "") {
document.getElementById("TitleField").innerHTML = "Your Title is : " + space;
}
}
and I got err in FireFox rror”space is undefined” why ?
In chrome “Uncaught TypeError:Cannot call method’split’ of Undefined”
Thx for helping.
This code will never work for any input.
stris a already part of result of split by=, i.e. it contains no=symbols.Then you split that result again by
=, which of course will return you one-element array andstr.split("=")[1]will always beundefined.Looks like you’re trying to read cookie value… but second
.split("=")is not needed at all.Ah, and you got different results in different browsers, cause they contain different data in their cookies.
PS: Instead of
while( space.indexOf('%20' )+1) space = space.replace(/%20/,' ');you may writespace = space.replace(/%20/g,' ');to replace all of them at once.