JavaScript检查浏览器扩展是否安装了Chrome,Firefox和Opera [英] JavaScript check if browser extension is installed for Chrome, Firefox and Opera

查看:182
本文介绍了JavaScript检查浏览器扩展是否安装了Chrome,Firefox和Opera的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想在我们的网站上显示自定义栏(通知如:安装我们的插件)如果未安装扩展程序,Chrome,Firefox和Opera。如果安装了扩展程序,则不会显示任何内容。



这个想法是

1.用户访问我们的网站出现消息栏 - 安装我们的扩展。

2.用户点击安装和扩展安装。无需用户打开它。

3.用户再次访问我们的网站,酒吧不会再出现,因为扩展安装。

我们谈仅用于安装检查,而不是Cookie



到目前为止,我只能找到Chrome的解决方案: http://blog.kotowicz.net/2012/02/intro-to-chrome-addons-hacking。 html

和Firefox: http:// webdevwonders。
Opera从未被提及。

有没有办法做到这一点歌剧,基于检查本地资源是扩展的一部分的想法:

chrome-extension:// - 扩展名ID - / blank.gif

Firefox Firefox://firebug/content/blank.gif



或其他:
是否有一个简单的方法来检查扩展名是安装如果扩展程序愿意合作,它可以宣传它的存在,如Chrome浏览器,Firefox和Opera?到文件很容易。例如:





扩展名可以是

  window。$$ myExt = ... 



<那么你可以通过检测扩展名

pre $ if(typeOf $$ myExt!=='undefined'){...

(或其中的任何变化)
$ b

获取页面 window






扩展名可以做
$ b $ pre $ $ $ $ $ document.body.classList.add(myExt-visited)

然后你可以检测到扩展名

  if(document.body.classList.contains(myExt-visited)){... 






扩展名可以是

  document.body.innerHTML + =< div ID ='MYEX t-toolbar'> ...
//或$('body')。append(< div id ='myExt-toolbar'> ...);

然后您可以通过

<$如果(document.getElementByID(myExt-toolbar)){...
//或if($(#myExt-toolbar)。 ..






或者,您可以

 < div id =myExt-replacement> 
...

和扩展名将会做

  var replacement = document.getElementByID(myExt-replacement); 
替换&& replacement.remove();






或者您可以做

  function onMyExtExists(){
...
}

以及扩展名将会做
$ b $ pre $ onMyExtExists&& onMyExtExists();



I want to show custom bar ( notification like: Install our plugin. ) on our site if extension is not installed for Chrome, Firefox and Opera. None will be displayed if extension is installed.

The idea is:
1. User visits our site and a bar with message appears - "Hey, install our extensions".
2. User clicks on install and extension is installed. No need for the user to open it.
3. User visit our site again and the bar does not appear again as the extension is installed.
We talk only for installation check, not cookies.

So far I was able to find solutions only for Chrome: http://blog.kotowicz.net/2012/02/intro-to-chrome-addons-hacking.html
and Firefox: http://webdevwonders.com/detecting-firefox-add-ons/
Opera is never mentioned.

Is there a way to do it for Opera, based on the idea of checking for a local resource which is part of the extension:
chrome-extension://--Extension ID--/blank.gif
Firefox chrome://firebug/content/blank.gif

Or else: Is there a simple way to check if extension is installed for Chrome, Firefox and Opera?

解决方案

If the extension is willing to cooperate, it could advertise its presence to the document easily. For example:


The extension could do

window.$$myExt = ...

Then you can detect the extension by

if(typeOf $$myExt !== 'undefined'){...

(or any variation thereof)

Obtaining the page window is somewhat tricky at least


The extension could do

document.body.classList.add("myExt-visited")

Then you could detect the extension by

if(document.body.classList.contains("myExt-visited")){...


The extension could do

document.body.innerHTML += "<div id='myExt-toolbar'>..."
// or $('body').append("<div id='myExt-toolbar'>...");

then you could detect the extension by

if(document.getElementByID("myExt-toolbar")){...
// or if($("#myExt-toolbar").length){...


alternatively, you could do

<div id="myExt-replacement">
   ...

and the extension would do

var replacement = document.getElementByID("myExt-replacement");
replacement && replacement.remove();


or you could do

function onMyExtExists(){
  ...
}

and the extension would do

onMyExtExists && onMyExtExists();

这篇关于JavaScript检查浏览器扩展是否安装了Chrome,Firefox和Opera的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆