The document.body.innerHTML.replace() replaces the url in the address bar.

Posted by divya on Stack Overflow See other posts from Stack Overflow or by divya
Published on 2010-12-30T10:13:49Z Indexed on 2011/01/09 16:54 UTC
Read the original article Hit count: 252

Filed under:

I am trying to make an extension as part of which i want certain words in the web pages to be highlighted. The document.body.innerHTML.replace() replaces the url in the address bar as well. So the moment this code gets exwecuted the page doesnt get loaded properly.. Is there a way around this problem?

onPageLoad: function(aEvent) {  
       var doc = aEvent.originalTarget;
        var str="the";
 var regex;
 var regex = new RegExp(str, "g");
    doc.body.innerHTML = doc.body.innerHTML.replace(regex,'<b>'+str+'</b>');
}

The listener is registered as follows in a browser.xul overlay:

window.addEventListener("load", function() {
  myExtension.init();
}, false);
var myExtension = {
  init: function() {
    var appcontent = document.getElementById("appcontent"); // browser
    if(appcontent)
      appcontent.addEventListener("DOMContentLoaded", myExtension.onPageLoad, false);
  }, 

© Stack Overflow or respective owner

Related posts about firefox-addon