Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add Google search in web page

Tags:

html

search

I'd like to add search to a static site. The simplest way is to simply query Google by appending "site:www.acme.com" to the actual query so that Google will limit search to that site.

Ideally, I'd like to do this in the browser, to avoid having to install PHP on the server. Using a form, I don't know how to append the search items:

<form action=http://www.google.com?q="site:www.acme.com+...">
<input type=text id=search_item>
</form>

Does someone know of a client-side solution? Should I use some JavaScript for this?

Thank you.


Edit: When using "method=get" and "input name=q value="site:www.acme.com "", the browser will indeed call Google with "www.google.com?q="site:www.acme.com some item", but I'd rather avoid presetting the input box with "site:www.acme.com" because users will find this odd and might remove it.

like image 902
Gulbahar Avatar asked Nov 14 '12 12:11

Gulbahar


1 Answers

You just need to set the form method to "get", add one extra hidden element with the site you want to search and it will automatically paste it behind the URL as such:

<form action="https://google.com/search" method="get">
<input type="hidden" name="sitesearch" value="http://acme.com" />
<input type="text" name="q" />
</form>

Because that is how HTML forms work by default.

like image 74
RadicalRaid Avatar answered Nov 15 '22 21:11

RadicalRaid