JavaScript check if browser extension is installed for Chrome, Firefox and Opera

对着背影说爱祢 提交于 2019-12-03 07:54:37
John Dvorak

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