how can i make a Google Internal Site Search开发者_Go百科 Script by JavaScript
Don't. Just use the standard form handling:
<form method="get" action="http://www.google.com/search">
<input type="text" name="q" value="" />
<input type="hidden" name="sitesearch" value="yoursitehere.com"/>
<input type="submit" value="Google Search" />
</form>
That's it. No javascript required.
http://jsfiddle.net/dWrsZ/
If you want it to open in a new window:
<form method="get" action="http://www.google.com/search" target="_blank"> <input type="text" name="q" value="" /> <input type="hidden" name="sitesearch" value="yoursitehere.com"/> <input type="submit" value="Google Search" /> </form>
Check here: http://jsfiddle.net/qEmhJ/
HTML:
<input type="text" id="q" />
<input type="button" value="search!" onclick="gsearch();" />
JavaScript:
function gsearch() {
var q=document.getElementById('q').value;
q+=' site:example.com';
window.open('http://www.google.com/search?q='+encodeURIComponent(q));
}
精彩评论