[英]How to detect search provider which has already been added?
I'm trying to build a feature like whenever a user comes to my site, I have added an option to add default search provider in their browser. 我正在尝试构建一个功能,例如每当用户访问我的网站时,我都添加了一个选项,以在其浏览器中添加默认搜索提供程序。 I have written a code like this for Firefox - 我已经为Firefox编写了这样的代码-
<script>
$(document).ready(function () {
var isFirefox = typeof InstallTrigger !== 'undefined';
if (isFirefox === false) {
$("#set-susper-default").remove();
$(".input-group-btn").addClass("align-search-btn");
$("#navbar-search").addClass("align-navsearch-btn");
}
if (window.external && window.external.IsSearchProviderInstalled) {
var isInstalled = window.external.IsSearchProviderInstalled("http://susper.com");
if (!isInstalled) {
$("#set-susper-default").show();
}
}
$("#install-susper").on("click", function () {
window.external.AddSearchProvider("http://susper.com/susper.xml");
});
$("#cancel-installation").on("click", function () {
$("#set-susper-default").remove();
});
});
</script>
User clicks on the install button and script runs and the site is added in search provider list. 用户单击安装按钮,脚本将运行,并且该站点已添加到搜索提供程序列表中。 If a user refreshes or again comes to my site, this feature again come. 如果用户刷新或再次访问我的网站,则此功能再次出现。 How should I detect it is already added so that whenever a user comes to my site next time it does not appear. 我应该如何检测它已被添加,以便每当用户下次访问我的网站时它都不会出现。
It would be great help if someone can help me out. 如果有人可以帮助我,那将是很大的帮助。 Thanks :) 谢谢 :)
Unfortunately you can't use IsSearchProviderInstalled
and AddSearchProvider
. 不幸的是,您不能使用IsSearchProviderInstalled
和AddSearchProvider
。 They are considered no-ops in Chrome, and should do nothing as HTML Standard describes, more info here: https://www.chromestatus.com/feature/5672001305837568 . 它们在Chrome浏览器中被视为无操作对象,并且不应该执行HTML标准所描述的任何操作,更多信息请参见: https : //www.chromestatus.com/feature/5672001305837568 。 For now AddSearchProvider
works in Firefox, but IsSearchProviderInstalled
will return always 0. You can try it by going to https://google.com and adding this code: external.IsSearchProviderInstalled("https://www.google.com");
现在AddSearchProvider
工作在Firefox,但IsSearchProviderInstalled
始终返回0。您可以去尝试它https://google.com并添加以下代码: external.IsSearchProviderInstalled("https://www.google.com");
in the console. 在控制台中。
Instead you should try adding search plugin autodiscovery into your webpage. 相反,您应该尝试将搜索插件自动发现添加到您的网页中。 To do so just add the <link>
element to the <head>
: 为此,只需将<link>
元素添加到<head>
:
<link rel="search"
type="application/opensearchdescription+xml"
title="searchTitle"
href="pluginURL">
More info about it here: https://developer.mozilla.org/en-US/Add-ons/Creating_OpenSearch_plugins_for_Firefox#Autodiscovery_of_search_plugins 此处的更多信息: https : //developer.mozilla.org/zh-CN/Add-ons/Creating_OpenSearch_plugins_for_Firefox#Autodiscovery_of_search_plugins
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.