views:

157

answers:

2

Hey Guys,

I was looking for a way to detect the browser extension I am building from my website and I need to alert my users in-case they are viewing my site without it. I have been able to do this in firefox, but I want to know is there a way I can do this in Google Chrome? Even if there is a hack to get this going I am fine.

+1  A: 

Sure. Create a content script specific to you site in the extension, and make it add an invisible marker in the DOM, eg:

$('body').append('<div style="display: none;" class="extension_enabled" />');

In the page, set a short timeout to check for this after the document is fully loaded, eg:

$(function() {
  setTimeout(function() {
    if ($('.extension_enabled').length > 0) {
      alert('Installed!');
    } else {
      alert('Not installed.');
    }
  }, 500);
});

NOTE: Code in jQuery format for simplicity. You can do it with raw javascript, of course.

Max Shawabkeh
+2  A: 

The official Google Chrome Extensions Developers' Guide has an item covering exactly this.

Scott Wolchok