I found a similar function using PHP:
google.load('search', '1');
google.setOnLoadCallback(function(){
var cse = new google.search.CustomSearchControl('Your unique CSE
code');
cse.enableAds('pub-your adsense publisher ID');
cse.draw('cse');
cse.setNoResultsString('No results for this query, try a different
search.');
cse.setResultSetSize(GSearch.FILTERED_CSE_RESULTSET);
cse.execute('<?php echo trim($_GET['q']); ?>');
}, true);
the variable "q" is used in my regular HTML form on other pages
On Oct 28, 4:59 am, Devraj <[email protected]> wrote:
> This is a follow up on my own post, I managed to inspect the loaded
> JavaScript and find out what messages it exposed and figured out how
> you can execute search as soon as the CSE widgets are loaded.
>
> This example gets the keywords from the URL.The script is a
> modification to the generated code from the CSE console.
>
> Hope its helpful to some of you out there.
>
> function getParameter(name) {
> name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
> var regexS = "[\\?&]"+name+"=([^&#]*)";
> var regex = new RegExp( regexS );
> var results = regex.exec( window.location.href );
> if( results == null ) return "";
> else return results[1];}
>
> google.load('search', '1');
> google.setOnLoadCallback(function(){
>
> var customSearchControl = new google.search.CustomSearchControl
> ('CSEID');
> customSearchControl.setResultSetSize
> (google.search.Search.FILTERED_CSE_RESULTSET);
> customSearchControl.draw('cse');
>
> var urlKeywords = getParameter('keywords');
> if(urlKeywords) {
> customSearchControl.input.value = urlKeywords;
> customSearchControl.execute();
> customSearchControl.input.focus();
>
> }
> }, true);
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google AJAX APIs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/google-ajax-search-api?hl=en
-~----------~----~----~----~------~----~------~--~---