Forum Moderators: open

Message Too Old, No Replies

Is there a script for this....

search on: All the Web - AltaVista - Google etc.

         

MrSchmidt

4:29 pm on Dec 29, 2004 (gmt 0)

10+ Year Member



Does anyone know if there is a script which I can make it so that on my search results page it would let me go to other search engines and search for that particular term by just clicking on a link. An example of this is when you do a search at dmoz.org it gives you other search engine options at the bottom of the results page. I operate a small niche search engine and would like to add this feature.
Thanks

adni18

4:48 pm on Dec 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Say your address was:

www.mysite.com/search.cgi?q=scarab+beetles+and+culture+symbols

Needless to say, this would be much more efficient if done at the server side, but it can be done.

<script language="javascript">
<!--
query=window.location.href.split("q=").split("&")[0];

//Here, put as many addresses as you want, and where you want the query search, put ###. For the text to display the link as, put that before the percent (%) sign.

urls=new Array("Search Google for ###%http://www.google.com/search?hl=en&q=###","Search Dictionary.com for ###%http://www.dictionary.com/search?q=###");

for(var quick=0;quick<urls.length;quick++)
{
hurry=urls[quick].replace(/\#\#\#/g,query);
document.write("<a href=\""+hurry.split("%")[1]+"\">"+hurry.split("%")[0]+"</a><br>");

}
//-->
</script>

Certainly, it can be cleaned up a bit, but it should work.

[1][edited by: adni18 at 4:51 pm (utc) on Dec. 29, 2004]

RonPK

4:48 pm on Dec 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Let's suppose the query is in a field called query:

<script type="text/javascript"> 
function searchwith(se) {
var kw = document.myform.query.value;
switch (se) {
case 'g' : location = 'http://www.google.com/search?q=' + kw; break;
case 'y' : location = 'http://search.yahoo.com/search?p=' + kw; break;
}
}
</script>

<form name="myform">
<input type="text" name="query" value="widget">
...
</form>

<a href="http://www.google.com/" onclick="searchwith('g'); return false">search with Google</a>
<a href="http://www.yahoo.com/" onclick="searchwith('y'); return false">search with Yahoo</a>

adni18

5:04 pm on Dec 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Minor fix for my code:

<script language="javascript">
<!--
query=window.location.href.split("q=")[1].split("&")[0];
//Here, put as many addresses as you want, and where you want the query search, put ###. For the text to display the link as, put that before the percent (%) sign.

urls=new Array("Search Google for ###%http://www.google.com/search?hl=en&q=###","Search Dictionary.com for ###%http://www.dictionary.com/search?q=###");

for(var quick=0;quick<urls.length;quick++)
{
hurry=urls[quick].replace(/\#{3}/g,query);
document.write("<a href=\""+hurry.split("%")[1]+"\">"+hurry.split("%")[0]+"</a><br>");
}
//-->
</script>

adni18

5:12 pm on Dec 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



And a further fix for my code, getting rid of the hex stuff:

<script language="javascript">
<!--
query=window.location.href.split("q=")[1].split("&")[0];
//Here, put as many addresses as you want, and where you want the query search, put ###. For the text to display the link as, put that before the percent (%) sign. Use a *** for the human-readable query

urls=new Array("Search Google for ***%http://www.google.com/search?hl=en&q=###","Search Dictionary.com for ***%http://www.dictionary.com/search?q=###");

for(var quick=0;quick<urls.length;quick++)
{
hurry=urls[quick].replace(/\#{3}/g,query);
readable=hurry.split("%")[0].replace(/\*{3}/g,unescape(query.replace(/\+/g," ")));
document.write("<a href=\""+hurry.split("%")[1]+"\">"+readable+"</a><br>")
}
//-->
</script>