I am working on a Google Custom Search implementation that uses the option to load search results in an iframe within another page.
Using this URL as the iframe's source (includes a sample query):
http://www.google.com/cse?cx=013856813593859657536:ss10an3on4k&cof=FORID:11&as_q=test
If I load this URL on a desktop browser, the custom search results are returned. If my user agent is a mobile browser (currently experiencing 开发者_Python百科this issue with Safari iOS 4.3, and Android) I get an empty page with a Javascript search box. This causes my users to have to enter search terms twice. Here is a screenshot of the returned page:
http://csuh.tv/0s032D1S3S0F3X161i16
Google seems to be user-agent sniffing (boo) in this regard, and borking mobile results. I need to either (1) fix this using some custom-search API options I have not found in their documentation or (2) prevent them from sniffing and screwing up the mobile results.
UPDATE: I solved this by presenting mobile clients with a search box that simply submitted to the regular Google search (i.e. http://google.com/search
) with a site:
term. The solution below works as well.
When you type in the search box and hit enter, you get a different URL. You could probably change the iframe's src to the below URL and it should work:
http://www.google.com/cse?cx=013856813593859657536:ss10an3on4k&cof=FORID:11&as_q=test#gsc.tab=0&gsc.q=test
As a last resort, and assuming it is in accordance with Google's TOS, you could have the iframe point to a page on your server that acts as a proxy to fetch the result from Google and outputs the resulting HTML. That way you have complete control over the user agent.
www.mywebsite.com/mysearchproxy.php?search=test
精彩评论