0

我正在尝试使用 opensearch 在我的网站 URL 上实现 Tab To Search。我按照 openSearch 文档中的步骤操作,但仍然没有为我工作。请帮我弄清楚我错过了什么。

我的 XML 文件:

<?xml version="1.0"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
 <ShortName>localhost</ShortName>
 <Description>Search localhost</Description>
 <Url type="text/html" method="get" template="localhost:8080/?query={searchTerms}"/>
</OpenSearchDescription>

我在 index.html 文件中的 Head 标签是:

<!doctype html>
<html>
<head>
    <link rel="search"
          type="application/opensearchdescription+xml"
          title="Google IFL"
          href="tabToSearch.xml">
 </head>

结果:每当我按下 Tab 按钮时,它都会跳转到下一个 url 在此处输入图像描述 在此处输入图像描述

4

1 回答 1

2

结构是正确的,问题是您忘记在模板中添加 http 协议。没有协议,它不会被添加到 chrome 中。

-  <Url type="text/html" method="get" template="localhost:8080/?query={searchTerms}"/>
+  <Url type="text/html" method="get" template="http://localhost:8080/?query={searchTerms}"/>

完成此操作后,您将能够在 Chrome 自定义搜索引擎设置中看到它。 在此处输入图像描述

但是,当您尝试搜索localhost但不搜索时,它会起作用localhost:8080。它仍将使用良好的端口进行搜索。这是因为搜索关键字将没有端口。

于 2021-01-20T15:04:46.983 回答