I have a hard coded webpage that I can add parts containing scripts. I need to add a script to change the word Attendees to Count throughout the page and the pages with in it. This is the code wrote and have been playing with but its not functioning.
<p> </p>
<script type="text/javascript">// <![CDATA[
document.body.innerHTML = document.body.innerHTML.replace(new RegExp("Attendees", "g"), "Count");
// ]]></script>
Pointy
415k62 gold badges600 silver badges633 bronze badges
1 Answer 1
Try this:
<script type="text/javascript">
window.onload = function(){
document.body.innerHTML =
document.body.innerHTML.replace(/Attendees/g, "Count");
}
</script>
You need to make sure your script runs after the page has completely loaded: window.onload\
Also check out the replace documentation.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace
answered Dec 17, 2013 at 16:12
iambriansreed
22.3k6 gold badges66 silver badges81 bronze badges
Sign up to request clarification or add additional context in comments.
6 Comments
Felix Kling
If the
<script> tag is placed at the end of the <body>, then this won't make a difference.user3111971
Thank you!This works on the first page only and will not run through the other layered pages. I need to run it through all layered pages.
user3111971
Any thoughts on getting it to run through layered pages?
iambriansreed
It sounds you are asking a new question. What exactly do you mean by layered pages?
user3111971
This is on a hard coded registration page so there are layered pages through the registration process. I need to do the same replacement throughout these layers, but each layered page does not its own coding. Sorry if this isn't clear, this old hard coded website is the death of me and I can't wait until we change.
|
default
</body>, then it might work. I don't see any issues with the actual JS (aside cleaning up the regex declaration by changing it to/Attendees/g)