Tag archives: search

How to create an mp3 Google search box for your website

Have you ever wanted to add a specialty Google search box for your website that only found mp3, xls, doc, or other files of specific extensions? Well using a little JavaScript and tweaking Google’s code, it’s very simple to add a specialty Google search box to your website.

Here’s an example of a search box that only finds mp3 files.
Try searching for Daft Punk

Google

Amazing, so how did I do this? Here’s the original JavaScript from Google to add a standard web search box to your website:

<!-- Search Google -->
<center>
<FORM method=GET action="http://www.google.com/search">
<input type=hidden name=ie value=UTF-8>
<input type=hidden name=oe value=UTF-8>
<TABLE style="background-color:#ffffff;"><tr><td>
<A HREF="http://www.google.com/">
<IMG SRC="http://www.google.com/logos/Logo_40wht.gif" ALT="Google" align="absmiddle" style="border:0;"></A>
<INPUT TYPE=text name=q size=25 maxlength=255 value="">
<INPUT type=submit name=btnG VALUE="Google Search">
</td></tr></TABLE>
</FORM>
</center>
<!-- Search Google -->

Here’s a little JavaScript you need to find only mp3 files. Notice, I am just using the “intitle” and “-” syntax to narrow the search results.

<!-- Search Script -->
function submitform() {
       var new_query="intitle:index.of \"mp3\" \"" +document.gs.query.value +"\"-htm -html -php -asp \"Last Modified\"";
       document.gs.query.value=new_query;
       }
<!-- End Search Script -->

In the above code, document.gs.query.value is just what the user originally typed.
Here’s the revised Google search code that implements the above JavaScript to make a specialty Google search happen:

<script type='text/javascript' src='search.js'></script>
<!-- Search Google --><center><form action="http://www.google.com/search" method="get" name="gs" onsubmit="return submitform();" ><input type="hidden" value="UTF-8" name="ie" /> <input type="hidden" value="UTF-8" name="oe" /><table style="background-color:#ffffff;">
<tr>
<td><a href="http://www.google.com/"> <img style="border:0;" alt="Google" src="http://www.google.com/logos/Logo_40wht.gif" /></a> <input type="text" maxlength="255" size="25" name="query" /> <input type="submit" value="mp3 Search" name="btnG" /></td>
</tr>
</table>
</form>
</center>
<!-- Search Google -->

If you wanted to make some money, you could modify Google’s Adsense Search Box to search for only mp3, mp4, mpeg, etc… However, that would violate the Google’s Adsense Terms of Service.