john
john

Reputation: 434

how can i make a Google Internal Site Search Script by JavaScript

how can i make a Google Internal Site Search Script by JavaScript

Upvotes: 1

Views: 3810

Answers (2)

Eric
Eric

Reputation: 97571

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>

Upvotes: 2

aularon
aularon

Reputation: 11110

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));

}

Upvotes: 0

Related Questions