location.href and Mozilla

M

Max of Mad

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
 
B

Brian Genisio

Max said:
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
 
K

kaeli

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
 
M

Max of Mad

Brian said:
Max of Mad wrote:

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
 
M

Max of Mad

kaeli said:
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
 

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

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top