![]() |
|
12.18.09 Adding A More Defined Search To Your Google Search Bar By Dave Taylor I have a Google search box on my site, thanks to your article How to add Google Search to Your Site, but want to automatically add a few words to the search string that the user enters. Is that even possible? If so, how do I modify the JavaScript code to make it work? Dave's Answer: Great question, and one that's come up quite a few times since I wrote that original Google search code. Seems like it's popular to not only have a search box on your site, but to tweak the actual search that you send to Google. Who knew? :-) Accomplishing this task, however, is quite a bit more complicated because what we have to do is actually tweak the form itself so that the word or words are grafted onto the search after the user has clicked the submit button but before the data is actually sent back to Google. I asked a developer friend of mine, Luke Kingland, to help out and he describes his solution thusly: "Instead of the user entering search terms directly into the "q" field that Google will read, we're going to have the user first enter their search terms into a temporary field named "custom_terms". The JavaScript that is then run when the user clicks "Submit" assembles the value for the "q" field (which is hidden) by setting it to both what the user typed in and the value of "additional_terms", which the site owner hard codes on the page."
![]() Continue reading this article.
|
|
|
|
-- DevWebProNL is an iEntry, Inc. publication -- iEntry, Inc. 2549 Richmond Rd. Lexington KY, 40509 © 2009 iEntry Inc. All Rights Reserved Privacy Policy Legal
|