Code works in IE but not in FF

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

  1. lolo

    lolo Guest

    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>
    lolo, Jan 18, 2005
    #1
    1. Advertising

  2. lolo

    RobG Guest

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

    --
    Rob
    RobG, Jan 18, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Keith G
    Replies:
    0
    Views:
    1,624
    Keith G
    Sep 8, 2003
  2. Pierre-Marc Fournier

    Template code works with g++ but not MSVC++

    Pierre-Marc Fournier, Jul 13, 2004, in forum: C++
    Replies:
    6
    Views:
    455
    Alf P. Steinbach
    Jul 13, 2004
  3. F. GEIGER
    Replies:
    3
    Views:
    749
    F. GEIGER
    Aug 6, 2004
  4. David Wang
    Replies:
    0
    Views:
    717
    David Wang
    Dec 1, 2006
  5. Replies:
    7
    Views:
    833
    Martin Gregorie
    Dec 6, 2006
Loading...

Share This Page