Code works in IE but not in FF

Discussion in 'Javascript' started by lolo, Jan 18, 2005.

  1. lolo

    lolo Guest


    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 ( == '__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.pasteHTML('<span name="__surligne__" style="color:black;
    background-color:yellow">' +str + '</span>');

    return false;

    lolo, Jan 18, 2005
    1. Advertisements

  2. lolo

    RobG Guest

    lolo wrote:

    Assigning innerHTML to a variable name may make innerHTML unavailable.

    Firefox does not support outerHTML, it is an IE thing (and maybe Opera,
    but don't quote me).
    RobG, Jan 18, 2005
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.