If you load the full blown Google AJAX Search API, that's not a problem. If you are using Local Search GControl, you have a
searchFormHint
option but not a method to trigger the search. With GGoogleBar you don't have either of them.Both GoogleBar and Local Search Control generate a form element with a text input field and a submit button. The form element of GoogleBar is not generated until the GoogleBar is opened. So we can assume that the form is the last one on your page and we can access it like:
var lastForm = document.forms.length - 1;
document.forms[lastForm].elements[0].value = "Music";
document.forms[lastForm].elements[1].click();
You have to define the GoogleBar to open initially by googleBarOptions:{showOnLoad:true}.
How to trigger the form access? There is no event that would tell us when the form is built. I ended up using onIdleCallback function plus a small timeOut. The onIdleCallback is triggered when GoogleBar is formed. It is triggered also after each search so I set a variable to make sure the seach is made only once.
It seems to work but with no quarantee.