location.href and Mozilla

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Max of Mad

    location.href and Mozilla


    Hi all,

    I wrote this a while back, but I was unable to get it to work for
    mozilla. Looked all over the place, but could not find anything on why.

    Basically, this has a dropdown of some search engines, and a text input
    for the search term. Click GO and it takes you to the selected search
    engine with the query.

    This works great on IE and Opera, but it will not work in Mozilla. My
    guess is that Moz doesn't like the window.location .href... I've tried
    just location.href, and a bunch of others, to no avail.

    using win2000, IE6, Opera 6.01, and Mozilla 1.6.

    Does anyone have any ideas?



    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <HTML>
    <HEAD>
    <META name="GENERATOR " content="notepa d.exe">
    <TITLE>Search </TITLE>
    </HEAD>
    <body bgcolor="#aaaaa a">

    <STYLE TYPE="text/css">
    A {COLOR: #ffffff; TEXT-DECORATION: none}
    </STYLE>

    <script language="JavaS cript">

    function GoSearch() {
    var eQuery;
    var goQuery;
    var Engine;

    Engine = sform.searcheng ine.value;
    eQuery = sform.squery.va lue;
    goQuery='';

    if (Engine == 'goog') { goQuery = 'http://www.google.com/search?q=' +
    eQuery; }
    if (Engine == 'aol') { goQuery =
    'http://search.aol.com/aolcom/search?query=' + eQuery; }
    if (Engine == 'hotb') { goQuery =
    'http://www.hotbot.com/default.asp?que ry=' + eQuery; }
    if (Engine == 'lyco') { goQuery =
    'http://search.lycos.co m/default.asp?que ry=' + eQuery; }
    if (Engine == 'over') { goQuery =
    'http://www.overture.co m/d/search/?Keywords=' + eQuery; }
    if (Engine == 'alta') { goQuery =
    'http://www.altavista.c om/web/results?q=' + eQuery; }
    if (Engine == 'all') { goQuery =
    'http://www.alltheweb.c om/search?cat=web& q=' + eQuery; }
    if (Engine == 'teo') { goQuery = 'http://s.teoma.com/search?q=' + eQuery; }
    if (Engine == 'yah') { goQuery =
    'http://search.yahoo.co m/search?ei=UTF-8&fr=sfp&p=' + eQuery; }

    if (goQuery != '') { window.location .href = (goQuery); }
    }
    </script>

    <form method="post" id="sform" name="sform" action="javascr ipt:GoSearch(); ">
    <br>Search &nbsp;
    <select name="searcheng ine">
    <option value="goog">Go ogle
    <option value="all">All TheWeb
    <option value="alta">Al tavista
    <option value="aol">AOL
    <option value="hotb">Ho tBot
    <option value="lyco">Ly cos
    <option value="over">Ov erture
    <option value="teo">Teo ma
    <option value="yah">Yah oo
    </select>
    &nbsp; for &nbsp;
    <input type="text" name="squery" value="">
    <button onClick="javasc ript:GoSearch() ;" value="Go" id=button1
    name=button1>Go </button>
    </form>


    </BODY>
    </HTML>



    Max of Mad
    --
    Leave a tone after the message
  • Brian Genisio

    #2
    Re: location.href and Mozilla

    Max of Mad wrote:
    [color=blue]
    >
    > Hi all,
    >
    > I wrote this a while back, but I was unable to get it to work for
    > mozilla. Looked all over the place, but could not find anything on why.
    >
    > Basically, this has a dropdown of some search engines, and a text input
    > for the search term. Click GO and it takes you to the selected search
    > engine with the query.
    >
    > This works great on IE and Opera, but it will not work in Mozilla. My
    > guess is that Moz doesn't like the window.location .href... I've tried
    > just location.href, and a bunch of others, to no avail.
    >
    > using win2000, IE6, Opera 6.01, and Mozilla 1.6.
    >
    > Does anyone have any ideas?
    >
    >
    >
    > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    > <HTML>
    > <HEAD>
    > <META name="GENERATOR " content="notepa d.exe">
    > <TITLE>Search </TITLE>
    > </HEAD>
    > <body bgcolor="#aaaaa a">
    >
    > <STYLE TYPE="text/css">
    > A {COLOR: #ffffff; TEXT-DECORATION: none}
    > </STYLE>
    >
    > <script language="JavaS cript">
    >
    > function GoSearch() {
    > var eQuery;
    > var goQuery;
    > var Engine;[/color]
    //////////////////////////////////////////////////

    var sform;

    if(document.get ElementById)
    sform = document.getEle mentById("sform ");
    else if (document.all)
    sform = document.sform;
    else
    return;
    //////////////////////////////////////////////////[color=blue]
    > Engine = sform.searcheng ine.value;
    > eQuery = sform.squery.va lue;
    > goQuery='';
    >
    > if (Engine == 'goog') { goQuery = 'http://www.google.com/search?q='
    > + eQuery; }
    > if (Engine == 'aol') { goQuery =
    > 'http://search.aol.com/aolcom/search?query=' + eQuery; }
    > if (Engine == 'hotb') { goQuery =
    > 'http://www.hotbot.com/default.asp?que ry=' + eQuery; }
    > if (Engine == 'lyco') { goQuery =
    > 'http://search.lycos.co m/default.asp?que ry=' + eQuery; }
    > if (Engine == 'over') { goQuery =
    > 'http://www.overture.co m/d/search/?Keywords=' + eQuery; }
    > if (Engine == 'alta') { goQuery =
    > 'http://www.altavista.c om/web/results?q=' + eQuery; }
    > if (Engine == 'all') { goQuery =
    > 'http://www.alltheweb.c om/search?cat=web& q=' + eQuery; }
    > if (Engine == 'teo') { goQuery = 'http://s.teoma.com/search?q=' +
    > eQuery; }
    > if (Engine == 'yah') { goQuery =
    > 'http://search.yahoo.co m/search?ei=UTF-8&fr=sfp&p=' + eQuery; }
    >
    > if (goQuery != '') { window.location .href = (goQuery); }
    > }
    > </script>
    >
    > <form method="post" id="sform" name="sform"
    > action="javascr ipt:GoSearch(); ">
    > <br>Search &nbsp;
    > <select name="searcheng ine">
    > <option value="goog">Go ogle
    > <option value="all">All TheWeb
    > <option value="alta">Al tavista
    > <option value="aol">AOL
    > <option value="hotb">Ho tBot
    > <option value="lyco">Ly cos
    > <option value="over">Ov erture
    > <option value="teo">Teo ma
    > <option value="yah">Yah oo
    > </select>
    > &nbsp; for &nbsp;
    > <input type="text" name="squery" value="">
    > <button onClick="javasc ript:GoSearch() ;" value="Go" id=button1
    > name=button1>Go </button>
    > </form>
    >
    >
    > </BODY>
    > </HTML>
    >
    >
    >
    > Max of Mad[/color]

    Ahhh.... This is easy. See, in Mozilla, you can type javascript: in the
    location, and the javascript error console will pop up, telling you what
    is wrong.

    In your case, it told me that "sform is not defined".

    This is because using sform they way you did only works in IE.

    To fix your problem, simply set the value before you use it... see
    inlined fix above. This change will work in most JS enabled browsers.

    Brian

    Comment

    • kaeli

      #3
      Re: location.href and Mozilla

      In article <qZPYb.347931$x y6.1733206@attb i_s02>, admin@127.0.0.1
      enlightened us with...[color=blue]
      >
      > Hi all,
      >
      > I wrote this a while back, but I was unable to get it to work for
      > mozilla. Looked all over the place, but could not find anything on why.
      >[/color]

      Well, valid html would help.


      This has nothing to do with the location property and everything to do
      with IE syntax (which Opera can mudge through) and invalid HTML.

      This works and is MUCH simpler.
      Watch for word-wrap.

      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
      "http://www.w3.org/TR/REC-html40/loose.dtd">
      <HTML>
      <HEAD>
      <TITLE>Search </TITLE>
      <STYLE TYPE="text/css">
      A {COLOR: #ffffff; TEXT-DECORATION: none}
      </STYLE>

      <script type="text/javascript" language="javas cript">
      function GoSearch()
      {
      var eQuery;
      var Engine;
      Engine = document.forms["sform"].elements["searchengi ne"].options
      [document.forms["sform"].elements["searchengi ne"].selectedIndex].value;
      eQuery = document.forms["sform"].elements["squery"].value;
      window.location = Engine+eQuery;
      }
      </script>
      </HEAD>
      <body bgcolor="#aaaaa a">

      <form method="post" id="sform" name="sform" action="" onSubmit="retur n
      false;">
      <br>Search &nbsp;
      <select name="searcheng ine">
      <option value="http://www.google.com/search?q=">Goog le</option>
      <option value="http://www.alltheweb.c om/search?cat=web& q=">
      AllTheWeb</option>
      <option value="http://www.altavista.c om/web/results?q=">Alt avista
      </option>
      <option value="http://search.aol.com/aolcom/search?query="> AOL
      </option>
      <option value="http://www.hotbot.com/default.asp?que ry=">HotBot
      </option>
      <option value="http://search.lycos.co m/default.asp?que ry=">Lycos
      </option>
      <option value="http://www.overture.co m/d/search/?Keywords=">
      Overture</option>
      <option value="http://s.teoma.com/search?q=">Teom a</option>
      <option value="http://search.yahoo.co m/search?ei=UTF-8&fr=sfp&p=">
      Yahoo</option>
      </select>
      &nbsp; for &nbsp;
      <input type="text" name="squery" value="">
      <input type="button" value="Go" id="button1" name="button1"
      onClick="GoSear ch()">
      </form>

      </BODY>
      </HTML>

      --
      --
      ~kaeli~
      Is it true that cannibals don't eat clowns because they
      taste funny?



      Comment

      • Max of Mad

        #4
        Re: location.href and Mozilla

        Brian Genisio wrote:
        [color=blue]
        > Max of Mad wrote:
        >[/color]

        <snip>
        [color=blue]
        >
        > Ahhh.... This is easy. See, in Mozilla, you can type javascript: in the
        > location, and the javascript error console will pop up, telling you what
        > is wrong.
        >
        > In your case, it told me that "sform is not defined".
        >
        > This is because using sform they way you did only works in IE.
        >
        > To fix your problem, simply set the value before you use it... see
        > inlined fix above. This change will work in most JS enabled browsers.
        >
        > Brian
        >[/color]


        Thanks Brian.

        Didn't know about the error console. That would have saved me a LOT of
        time, on several things.

        And thanks for the sform fix. It works now.

        Much appreciated! I learn something new every day.


        Max of Mad
        --
        Leave a tone after the message

        Comment

        • Max of Mad

          #5
          Re: location.href and Mozilla

          kaeli wrote:
          [color=blue]
          > In article <qZPYb.347931$x y6.1733206@attb i_s02>, admin@127.0.0.1
          > enlightened us with...
          >[color=green]
          >>Hi all,
          >>
          >>I wrote this a while back, but I was unable to get it to work for
          >>mozilla. Looked all over the place, but could not find anything on why.
          >>[/color]
          >
          >
          > Well, valid html would help.
          >
          >
          > This has nothing to do with the location property and everything to do
          > with IE syntax (which Opera can mudge through) and invalid HTML.
          >
          > This works and is MUCH simpler.
          > Watch for word-wrap.
          >
          > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
          > "http://www.w3.org/TR/REC-html40/loose.dtd">
          > <HTML>
          > <HEAD>
          > <TITLE>Search </TITLE>
          > <STYLE TYPE="text/css">
          > A {COLOR: #ffffff; TEXT-DECORATION: none}
          > </STYLE>
          >
          > <script type="text/javascript" language="javas cript">
          > function GoSearch()
          > {
          > var eQuery;
          > var Engine;
          > Engine = document.forms["sform"].elements["searchengi ne"].options
          > [document.forms["sform"].elements["searchengi ne"].selectedIndex].value;
          > eQuery = document.forms["sform"].elements["squery"].value;
          > window.location = Engine+eQuery;
          > }
          > </script>
          > </HEAD>
          > <body bgcolor="#aaaaa a">
          >
          > <form method="post" id="sform" name="sform" action="" onSubmit="retur n
          > false;">
          > <br>Search &nbsp;
          > <select name="searcheng ine">
          > <option value="http://www.google.com/search?q=">Goog le</option>
          > <option value="http://www.alltheweb.c om/search?cat=web& q=">
          > AllTheWeb</option>
          > <option value="http://www.altavista.c om/web/results?q=">Alt avista
          > </option>
          > <option value="http://search.aol.com/aolcom/search?query="> AOL
          > </option>
          > <option value="http://www.hotbot.com/default.asp?que ry=">HotBot
          > </option>
          > <option value="http://search.lycos.co m/default.asp?que ry=">Lycos
          > </option>
          > <option value="http://www.overture.co m/d/search/?Keywords=">
          > Overture</option>
          > <option value="http://s.teoma.com/search?q=">Teom a</option>
          > <option value="http://search.yahoo.co m/search?ei=UTF-8&fr=sfp&p=">
          > Yahoo</option>
          > </select>
          > &nbsp; for &nbsp;
          > <input type="text" name="squery" value="">
          > <input type="button" value="Go" id="button1" name="button1"
          > onClick="GoSear ch()">
          > </form>
          >
          > </BODY>
          > </HTML>
          >[/color]

          Thanks kaeli,

          My html did leave a lot to be desired. It looks like I have some other
          stuff to fix besides this.

          Thanks for your input, and your version works great, too.

          Much appreciated!


          Max of Mad
          --
          Leave a tone after the message

          Comment

          Working...