OpenSearch 描述文档发现和 Chrome
我试图弄清楚如何使用 OpenSearch 宣传我的 Web 应用程序的搜索端点(请参阅 http: //www.opensearch.org/Specifications/OpenSearch/1.1#OpenSearch_description_document),但即使是我最简单的示例也不起作用。我的 index.html
包含:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
<head profile="http://a9.com/-/spec/opensearch/1.1/">
<link title="Search" rel="search" type="application/opensearchdescription+xml" href="osdd.xml"/>
</head>
<body>
hello
</body>
</html>
和 osdd.xml
包含:
<?xml version="1.0" encoding="UTF-8"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/" xmlns:moz="http://www.mozilla.org/2006/browser/search/">
<ShortName>test</ShortName>
<Description>test</Description>
<Url type="text/html" template="http://example.com?q={searchTerms}"/>
</OpenSearchDescription>
但似乎没有任何效果。 Chrome 的“选项卡搜索”行为没有显示,并且使用开发者工具 Chrome 似乎根本没有加载 osdd.xml
。
有什么线索吗?
I'm trying to figure out how to advertise my web application's search endpoint using OpenSearch (see http://www.opensearch.org/Specifications/OpenSearch/1.1#OpenSearch_description_document), but even my simplest example does not work. I have index.html
with:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
<head profile="http://a9.com/-/spec/opensearch/1.1/">
<link title="Search" rel="search" type="application/opensearchdescription+xml" href="osdd.xml"/>
</head>
<body>
hello
</body>
</html>
And osdd.xml
containing:
<?xml version="1.0" encoding="UTF-8"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/" xmlns:moz="http://www.mozilla.org/2006/browser/search/">
<ShortName>test</ShortName>
<Description>test</Description>
<Url type="text/html" template="http://example.com?q={searchTerms}"/>
</OpenSearchDescription>
But nothing appears to work. Chrome's "tab to search" behavior does not show up, and using the developer tools Chrome does not seem to be loading osdd.xml
at all.
Any clues?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
osdd.xml 的加载未显示在“开发人员工具”>“开发人员工具”上网络选项卡。
http://code.google.com/p/chromium/issues /detail?id=58801#c3(评论3)提到您需要至少搜索一次才能添加搜索引擎。
我还发现您需要从“设置”>“删除现有搜索引擎”。管理搜索引擎并重新启动浏览器以查看 osdd 文件更改的效果。
Loading of the osdd.xml does not show up on the Developer Tools > Network tab.
http://code.google.com/p/chromium/issues/detail?id=58801#c3 (comment 3) mentions that you need to search at least once to add the search engine.
I also discovered that you need to delete existing search engines from the Settings > Manage Search Engines and restart the browser to see effects of changes to the osdd file.
很抱歉挖掘这个线程,但我遇到了类似的问题并设法解决了它,所以如果有人发现它,我将我的发现留在这里。
就我而言,XML 文件不是 UTF-8,因此 Chrome 无法正确加载。请确保您的文件采用 UTF-8 格式。
干杯!
Sorry for digging up this thread but I had a similar issue and managed to resolve it, so I leave my findings here if anyone finds it.
In my case, the XML file wasn't on UTF-8 thus not being correctly loaded by Chrome. Please ensure your file is on UTF-8.
Cheers!
在这里添加一些最新信息。我找不到任何正式的证据,但似乎 Android 上的 Chrome 在 2018 年 9 月的某个地方改变了何时在设置中显示新搜索引擎的逻辑。在此之前,它使用当用户简单导航到该网站时即可工作。进行此更改后,搜索引擎并未立即显示在设置中。如果我访问具有开放搜索元标记的网站,我就能使其工作。然后转到另一个站点,然后再回来。直到第二次才出现。为了让用户更方便,我添加了一个隐藏的 iframe,它重定向到另一个站点(我控制的),并在该站点上添加了 2 秒后重定向回原始站点的重定向。它似乎适用于我测试的所有设备(一些三星设备)。
我在此处看到评论说只会查看 opensearch 文档当用户位于根节点(mysite.com/ 但不是 mysite.com/foo)时。我的网站正在关注此评论,并且我没有尝试其他方式,因此我无法批准或拒绝这是否重要。
Adding some more recent info here. I couldn't find any formal proof for it, but it seems like Chrome on Android changed the logic of when to show a new search engine in the settings, somewhere in September 2018. Before that, it used to work when the user simple navigated to the site. After this change, the search engine didn't show up immediately in the settings. I was able to make it work, if I go to my site that has open search meta tag. Then go to another site, and then come back. It only showed up on the second time. To make it easier for the user, I add a hidden iframe, that redirects to another site (which I control), and on that site I added a redirect back to the original site, after 2 seconds. It seems to work on all the devices I tested (a few samsung devices).
I saw comments here that says that the opensearch doc will only be looked for when the user is at the root node (mysite.com/ but not mysite.com/foo). My site is following this comment, and I didn't try otherwise, so I can't approve or deny if this is important.