javascript code does'nt work in firefox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sedigh mohseni
    New Member
    • Feb 2011
    • 64

    javascript code does'nt work in firefox

    hi

    i have a textbox in the first page of the site and there is a submit button next to that for search about favorite product that is put there for inform customers that such a product there is or not and actually these items are inside of the form tag

    i have another page and inside this page name of the products are written as a text , this page is specially for search in for example suppose products.html .

    i have a javascript code that is called after that user typed name of favorite product inside of textbox and click submit button.

    after click search button if there is such user's favorite product
    user transform to products.html and matching names are highlighted and show to user.

    but my problem is that my javascript code works in IE browser properly but unfortunately not in firefox

    would you please help me.
    my javascript code is as follow

    Code:
      <script language="javascript" type="text/javascript" >
    var NS4 = (document.layers);   
    var IE4 = (document.all);
    var win = window;   
    var n   = 0;
    function findInPage(str) {
      var txt, i, found;
      if (str == "")
        return false;
      if (NS4) {
        if (!win.find(str))
          while(win.find(str, false, true))
            n++;
        else
          n++;
        if (n == 0)
          alert("Not found.");
      }
      if (IE4) {
        txt = win.document.body.createTextRange();
        for (i = 0; i <= n && (found = txt.findText(str)) != false; i++) {
          txt.moveStart("character", 1);
          txt.moveEnd("textedit");
        }
        if (found) {
          txt.moveStart("character", -1);
          txt.findText(str);
          txt.select();
          txt.scrollIntoView();
          n++;
        }
        else {
          if (n > 0) {
            n = 0;
            findInPage(str);
          }
          else
            alert("((unfortunately, there is'nt any product matching with yours)) ");
       }
      }
      return false;
    }
              </script>
    in advance, i appreciate you
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    this script seems terribly outdated or do your customers use Netscape Navigator 4 (already dead) or Internet Explorer 4 (current version is 8)?

    Comment

    • sedigh mohseni
      New Member
      • Feb 2011
      • 64

      #3
      i got this script from internet and i did'nt write it myself , can i change some statements or some conditional statements for work properly with other browsers specially IE7, IE8 ,firefox3 and maybe firefox4.

      thanks alot for your help.

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        it might be easier to find a new one or rewrite it from scratch. look into Mozilla Developer Network for a description of what is possible in Firefox.

        PS. since the version turnaround of Firefox is quite high, you only need to consider FF4 and FF5

        Comment

        • NitinSawant
          Contributor
          • Oct 2007
          • 271

          #5
          best way to avoid these errors is that
          import jquery into ur page and rewrite the function

          Comment

          Working...