Javascript Search And Replace Of Text In Web Page After It Loads
Sun, 05/20/2007 - 14:43 adminThis is the code to use when a search and replace operation in a web page after it loads is needed. I developed it to solve a problem with an encoded PHP script I bought where it was impossible for me to change the PHP source code.
You insert this in the HEAD section of the html document
< script type="text/javascript" >
function myscript() {
input = 'Text To Be Changed';
output='New Text';
document.body.innerHTML = document.body.innerHTML.replace(input,output);
}
< /script >
then you change the body tag like this
< body OnLoad = "myscript();" >
so when the page loads momentarily you will see the 'Text to be changed'
and instantly it will change to 'New Text'
If the script does not work or works in undesirable ways one quick fix is to enter the input text like this
String.fromCharCode(84)+"ext To Be Changed'
where 84 is the ASCII code of T .
if the script still does not work then you can enter the input text using only the String.from.CharCode() function like this
String.fromCharCode(numX,numX,...,numX)
where numx is the ASCII code of the characters the input text consists of.