Thread: JS replace help
View Single Post
  #4 (permalink)  
Old Dec 6th, 2007, 02:52
Rakuli's Avatar
Rakuli Rakuli is offline
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: JS replace help

I think it would be better to have this guy change the text himself

You can acheive this in a fairly uneconomical way using

Code: Select all
<script type="text/javascript">

// get the text in the page
var bodytext = document.getElementsByTagName('body')[0].innerHTML;

// now loop through 5 times

for (i=0; i< 5; i ++)
{
       // replace the word (with matched word to preserve case
       bodytext = bodytext.replace(/[\s]{1}(telecom)[\s]{1}/i, " $1munications ");
}
// write the new body
document.getElementsByTagName('body')[0].innerHTML = bodytext;
</script>
Place that just before the </body> tag in your document.
Reply With Quote