views:

34

answers:

2
var loc_array = document.location.href.split('/');
var linkElement = document.getElementById("waBackButton");
var newT = document.createTextNode(loc_array[loc_array.length-2]); 
var repl = newT.replace('%20',' ');
linkElement.appendChild(repl);

Anyone know why this causes the text to not show up?

A: 

Why not just do

unescape(document.location.href);
Robusto
Where would that go though. I have .split() on the end.
Bry4n
I got it to work!
Bry4n
Robusto
A: 

Anyone know why this causes the text to not show up?

newT is created by document.createTextNode, which returns a Text object - not a String object.

Observing the Text prototype shows there is no replace function. The closest would be replaceWholeText.

E.g.:

var newT = document.createTextNode(loc_array[loc_array.length-2]); 
newT.replaceWholeText(unescape(newT.valueOf());

As others have already mentioned, though, you should just create the text node from unescape directly.

Like:

linkElement.appendChild(document.createTextNode(unescape(loc_array[loc_array.length-2])));
Matt
Never use `escape`/`unescape`. It is **not** the same thing as URL-encoding, it's a non-standard encoding scheme used only by JavaScript. URL-encoding is available under `encodeURIComponent`/`decodeURIComponent`.
bobince