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>
 
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).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,265
Messages
2,571,069
Members
48,771
Latest member
ElysaD

Latest Threads

Top