Code works in IE but not in FF


L

lolo

Hi,

I have this piece of code which works in IE but not in FF. The code find all
words in actual page who correspond to str and highlight them.

Thanx for your help


<script language="JavaScript">

var win = window; // window to search.
var n = 0;

function findInPage(str) {
var txt, i, found;
var listEls = document.getElementsByTagName("span");

for (i = listEls.length - 1 ; i >= 0 ; i--) {
if (listEls.name == '__surligne__') {
var innerHTML = listEls.innerHTML;
listEls.outerHTML = innerHTML;
}
}

if (str == "")
return false;

txt = win.document.body.createTextRange();

while ( txt.findText(str) != false) {
txt.moveStart("character", -1);
txt.moveEnd("textedit");
txt.findText(str);
txt.pasteHTML('<span name="__surligne__" style="color:black;
background-color:yellow">' +str + '</span>');
}

return false;
}

</script>
 
Ad

Advertisements

R

RobG

lolo wrote:
[...]
var innerHTML = listEls.innerHTML;


Assigning innerHTML to a variable name may make innerHTML unavailable.
listEls.outerHTML = innerHTML;


Firefox does not support outerHTML, it is an IE thing (and maybe Opera,
but don't quote me).
 

Top