Tech Support banner

Status
Not open for further replies.
1 - 3 of 3 Posts

·
Registered
Joined
·
68 Posts
Discussion Starter · #1 · (Edited)
Onload Replacements

I am trying to generate a code via php or javascript that will replace specified strings upon the webpage being loaded. For example:

"<smiley>" = "<img src='imagename.jpg'>"

Thereby stating that if in my body text if I were to enter "<smiley>" it would replace it with the specified image at the time the page is loaded.
 

·
Registered
Joined
·
68 Posts
Discussion Starter · #2 · (Edited)
Fixed!

Ok, apparently you can't use the "<" or ">" characters in the string to be searched for, that was my problem. Here is the code for anyone else who'd like to know:

<script>
function fixcode(input) {
input = input.replace("!smiley", "<img src='smile.jpg'>");
input = input.replace("!frowny", "<img src='frown.jpg'>");
return input;
}
function fixit() {
document.getElementsByTagName("body")[0].innerHTML = fixcode(document.getElementsByTagName("body")[0].innerHTML);
}
</script>
<body onload="fixit();">
testing a smiley: !smiley & then a frowny: !frowny
 
1 - 3 of 3 Posts
Status
Not open for further replies.
Top