Echo The Referrer's Keywords in Your Search Widget

If you have a search tool on your blog or web page, you can improve usablility by echoing the referrer's search keywords. That way, anyone that arrives at your site from a search engine can click through to continue their search.

This works with Google, Yahoo and MS Live.

Add the following script block to your page after the HTML for the search tool.

You might need to change getElementById()'s parameter from "sbi" to the ID of your search field. "sbi" works with Adsense for Search.

  1. <script type="text/javascript">  
  2. var searchFld = document.getElementById("sbi");  
  3. if (searchFld != null)  
  4. {  
  5.   var keywords = document.referrer.match(/[pq]=.*?\&/);  
  6.   if (keywords != null && keywords.length > 0)  
  7.     searchFld.value = keywords[0].replace(/[pq]=/,"").replace(/(\+|%20|\&)/g, " ");  
  8. }  
  9. </script>   

If your search tool is in a Blogger HTML/Javascript widget like mine, you can edit your widget and insert my script in there. Just make sure it goes at the bottom.


Nigel said…
is it possible to append the results in a E.g .txt file on the Server


Popular Posts