How to Redirect a Search Form to a Site-Scoped Google Search

Programming - Mar 31, 2024

This is just a tiny little trick that might be helpful on a site where you don’t have the time or desire to build out a really good on-site search solution. itself can perform searches scoped to one particular site. The trick is getting people there using that special syntax without them even knowing it.

Make a search form:

<form action="" target="_blank" type="GET">

     Search CSS-Tricks on Google: 
     <input type="search" name="q">

  <input type="submit" value="Go">


When that form is submitted, we’ll intercept it and change the value to include the special syntax:

var form = document.querySelector("form");

form.addEventListener("submit", function (e) {
  var search = form.querySelector("input[type=search]");
  search.value = " " + search.value;

That’s all.

Previous Next
We respect the property rights of others, and are always careful not to infringe on their rights, so authors and publishing houses have the right to demand that an article or book download link be removed from the site. If you find an article or book of yours and do not agree to the posting of a download link, or you have a suggestion or complaint, write to us through the Contact Us .
Read More