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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top