I looking for an alternative to the code below, it works fine, but it kills other javascripts running on the page, I guess I'm redeclaring the page or something so do I have any other options, beside getelementbyid, its just random text forund anywhere on the page var page = document.body.innerHTML=document.body.innerHTML=page.replace(/this/g, 'with this'); Code (markup): EDIT: emm, document.body is only between the <body tags, what should I be using to include the <head
Doing a global search and replace on the entire document.body is likely to be an intensive process because you're often dealing with (essentially) a very large string. Every insertion will require reconstructing the document.body contents. It would be better to copy document.body into a variable, do your search and replace on that data, and then set document.body equal to that variable. It would be even better if you could limit the process to a given section of your document - a specific <DIV>, for example. It would be best if you could do this server-side before sending the document to the user. Good luck!
It doesn't run on a website, its running through the browser... its part of a firefox addon. The majority of sites are fine, but when you load DP for example it has a lot of java going on and the above doesn't return header scripts, so thats what I'm looking for.
Maybe try: document.getElementsByTagName("html")[0].innerHTML Code (markup): or document.getElementsByTagName("head")[0].innerHTML Code (markup): Is the idea of this script to modify the documents HTML or to store it within the variable 'page' ??