Redirecting a Search Form to a Site-Scoped Google Search
If you don't have time or interest in building a full on-site search, Google can search a single site for you. The catch is the special syntax, and the goal is to get users there without exposing it to them.
Start with a search form:
<form action="https://google.com/search" target="_blank" type="GET">
<label>
Search CSS-Tricks on Google:
<input type="search" name="q">
</label>
<input type="submit" value="Go">
</form>
Then intercept the submit and rewrite the value with the scoped-site syntax:
var form = document.querySelector("form");
form.addEventListener("submit", function (e) {
e.preventDefault();
var search = form.querySelector("input[type=search]");
search.value = "site:css-tricks.com " + search.value;
form.submit();
});
That's the whole technique.



