By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,400 Members | 1,335 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,400 IT Pros & Developers. It's quick & easy.

location.href and Mozilla

P: n/a

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="notepad.exe">
<TITLE>Search</TITLE>
</HEAD>
<body bgcolor="#aaaaaa">

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

<script language="JavaScript">

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

Engine = sform.searchengine.value;
eQuery = sform.squery.value;
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?query=' + eQuery; }
if (Engine == 'lyco') { goQuery =
'http://search.lycos.com/default.asp?query=' + eQuery; }
if (Engine == 'over') { goQuery =
'http://www.overture.com/d/search/?Keywords=' + eQuery; }
if (Engine == 'alta') { goQuery =
'http://www.altavista.com/web/results?q=' + eQuery; }
if (Engine == 'all') { goQuery =
'http://www.alltheweb.com/search?cat=web&q=' + eQuery; }
if (Engine == 'teo') { goQuery = 'http://s.teoma.com/search?q=' + eQuery; }
if (Engine == 'yah') { goQuery =
'http://search.yahoo.com/search?ei=UTF-8&fr=sfp&p=' + eQuery; }

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

<form method="post" id="sform" name="sform" action="javascript:GoSearch();">
<br>Search &nbsp;
<select name="searchengine">
<option value="goog">Google
<option value="all">AllTheWeb
<option value="alta">Altavista
<option value="aol">AOL
<option value="hotb">HotBot
<option value="lyco">Lycos
<option value="over">Overture
<option value="teo">Teoma
<option value="yah">Yahoo
</select>
&nbsp; for &nbsp;
<input type="text" name="squery" value="">
<button onClick="javascript:GoSearch();" value="Go" id=button1
name=button1>Go</button>
</form>
</BODY>
</HTML>

Max of Mad
--
Leave a tone after the message
Jul 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Max of Mad wrote:

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="notepad.exe">
<TITLE>Search</TITLE>
</HEAD>
<body bgcolor="#aaaaaa">

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

<script language="JavaScript">

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

var sform;

if(document.getElementById)
sform = document.getElementById("sform");
else if (document.all)
sform = document.sform;
else
return;
////////////////////////////////////////////////// Engine = sform.searchengine.value;
eQuery = sform.squery.value;
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?query=' + eQuery; }
if (Engine == 'lyco') { goQuery =
'http://search.lycos.com/default.asp?query=' + eQuery; }
if (Engine == 'over') { goQuery =
'http://www.overture.com/d/search/?Keywords=' + eQuery; }
if (Engine == 'alta') { goQuery =
'http://www.altavista.com/web/results?q=' + eQuery; }
if (Engine == 'all') { goQuery =
'http://www.alltheweb.com/search?cat=web&q=' + eQuery; }
if (Engine == 'teo') { goQuery = 'http://s.teoma.com/search?q=' +
eQuery; }
if (Engine == 'yah') { goQuery =
'http://search.yahoo.com/search?ei=UTF-8&fr=sfp&p=' + eQuery; }

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

<form method="post" id="sform" name="sform"
action="javascript:GoSearch();">
<br>Search &nbsp;
<select name="searchengine">
<option value="goog">Google
<option value="all">AllTheWeb
<option value="alta">Altavista
<option value="aol">AOL
<option value="hotb">HotBot
<option value="lyco">Lycos
<option value="over">Overture
<option value="teo">Teoma
<option value="yah">Yahoo
</select>
&nbsp; for &nbsp;
<input type="text" name="squery" value="">
<button onClick="javascript:GoSearch();" value="Go" id=button1
name=button1>Go</button>
</form>
</BODY>
</HTML>

Max of Mad


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

Jul 20 '05 #2

P: n/a
In article <qZPYb.347931$xy6.1733206@attbi_s02>, ad***@127.0.0.1
enlightened us with...

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.


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="javascript">
function GoSearch()
{
var eQuery;
var Engine;
Engine = document.forms["sform"].elements["searchengine"].options
[document.forms["sform"].elements["searchengine"].selectedIndex].value;
eQuery = document.forms["sform"].elements["squery"].value;
window.location = Engine+eQuery;
}
</script>
</HEAD>
<body bgcolor="#aaaaaa">

<form method="post" id="sform" name="sform" action="" onSubmit="return
false;">
<br>Search &nbsp;
<select name="searchengine">
<option value="http://www.google.com/search?q=">Google</option>
<option value="http://www.alltheweb.com/search?cat=web&q=">
AllTheWeb</option>
<option value="http://www.altavista.com/web/results?q=">Altavista
</option>
<option value="http://search.aol.com/aolcom/search?query=">AOL
</option>
<option value="http://www.hotbot.com/default.asp?query=">HotBot
</option>
<option value="http://search.lycos.com/default.asp?query=">Lycos
</option>
<option value="http://www.overture.com/d/search/?Keywords=">
Overture</option>
<option value="http://s.teoma.com/search?q=">Teoma</option>
<option value="http://search.yahoo.com/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="GoSearch()">
</form>

</BODY>
</HTML>

--
--
~kaeli~
Is it true that cannibals don't eat clowns because they
taste funny?
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 20 '05 #3

P: n/a
Brian Genisio wrote:
Max of Mad wrote:

<snip>

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

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
Jul 20 '05 #4

P: n/a
kaeli wrote:
In article <qZPYb.347931$xy6.1733206@attbi_s02>, ad***@127.0.0.1
enlightened us with...
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.

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="javascript">
function GoSearch()
{
var eQuery;
var Engine;
Engine = document.forms["sform"].elements["searchengine"].options
[document.forms["sform"].elements["searchengine"].selectedIndex].value;
eQuery = document.forms["sform"].elements["squery"].value;
window.location = Engine+eQuery;
}
</script>
</HEAD>
<body bgcolor="#aaaaaa">

<form method="post" id="sform" name="sform" action="" onSubmit="return
false;">
<br>Search &nbsp;
<select name="searchengine">
<option value="http://www.google.com/search?q=">Google</option>
<option value="http://www.alltheweb.com/search?cat=web&q=">
AllTheWeb</option>
<option value="http://www.altavista.com/web/results?q=">Altavista
</option>
<option value="http://search.aol.com/aolcom/search?query=">AOL
</option>
<option value="http://www.hotbot.com/default.asp?query=">HotBot
</option>
<option value="http://search.lycos.com/default.asp?query=">Lycos
</option>
<option value="http://www.overture.com/d/search/?Keywords=">
Overture</option>
<option value="http://s.teoma.com/search?q=">Teoma</option>
<option value="http://search.yahoo.com/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="GoSearch()">
</form>

</BODY>
</HTML>


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
Jul 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.