Making usage of Google Chrome's OmniBox [TAB] Feature for/on personal website?

限于喜欢 提交于 2019-12-03 05:08:55

问题


I think the title explains it all but I am going deeper into my question anyway:

How can I make use of the Chrome's Omnibox [TAB] feature for my website?

As many users requested me to implement that feature on the site, I did research on the OpenSearchDescription and was very successful in implementation with the FireFox and IE7/IE8 Searchbar.

Yet the implementation didn't quite work for the Chrome Omnibox [TAB] feature..

Can you help me with that?

My OSD.xml code:

<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/"
                       xmlns:moz="http://www.mozilla.org/2006/browser/search/">
<ShortName>MySite</ShortName>
<Description>My Site</Description>
<InputEncoding>UTF-8</InputEncoding>
<Image width="16" height="16" type="image/x-icon">http://MySite.com/favicon.ico</Image>
<Url type="application/x-suggestions+json" method="GET"
     template="http://ff.search.yahoo.com/gossip?output=fxjson&amp;command={searchTerms}" />
<Url type="text/html" method="POST" template="http://MySite.com/query.php">
  <Param name="sString" value="{searchTerms}"/>
</Url>
<Url type="application/x-suggestions+json" template="suggestionURL"/>
<moz:SearchForm>http://www.MySite.com</moz:SearchForm>
</OpenSearchDescription>

And this is the link to the osd file on my page:

<link rel="search" type="application/opensearchdescription+xml" title="MySite" href="/opensearch.xml" />

回答1:


I've compared what you have against the OpenSearchDescription on my own site and I cannot see why yours is not working. The only real difference is that you are using POST to search whereas I am using GET. According to this page, IE7 does not support POST requests, so it may be that other browsers also do not support POST.

The one on my site definitely works in IE8, Chrome 3.0 and FF 2.0+. Feel free to compare them yourself and see if you can spot a difference: opensearch.XML




回答2:


Getting OSD (OpenSearchDescription) work under Google Chrome or IE7 / IE8 isn't as difficult as mentioned or that these browsers don't support POST requests.

With a little bit of tweaking, I found a workaround to the entire problem.

My initial code:

<Url type="text/html" method="POST" template="http://MySite.com/query.php">
  <Param name="sString" value="{searchTerms}"/>
</Url>

This code points directly to the query page and passes the value for the sString attribute on my POST request.

That works perfectly on FireFox but doesn't quite work well on IE7/IE8 or Google Chrome (I didn't test with Opera or Safari yet..).


Altering the code to the following piece:

<Url type="text/html" template="http://MySite.com/query.php?sString={searchTerms}"></Url>
  • Removing method="POST" from the element
  • Replacing /query.php with the actual page call: /query.php?sString={searchTerms}
  • Removing the now unnecessary "<Param name="sString" value="{searchTerms}"/>"

Resolved my problem of incompatibility with those browsers.

All calls are directly headed to the query page and even it initially was a POST request, it now work on both IE7/IE8 and Google Chrome.

Thanks again adrianbanks for providing me with your xml file which led to the solution!



来源:https://stackoverflow.com/questions/1317051/making-usage-of-google-chromes-omnibox-tab-feature-for-on-personal-website

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!