Skip to content

Instantly share code, notes, and snippets.

@TrevorJTClarke
Created April 6, 2015 17:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TrevorJTClarke/cc762bd22c95fc826aed to your computer and use it in GitHub Desktop.
Save TrevorJTClarke/cc762bd22c95fc826aed to your computer and use it in GitHub Desktop.
Chrome Inline Install Angular Directive
/**
* chromeInstall
* a directive for inline install of a chrome extension from a website using Angular
*
* Make sure that the head meta data contains:
* <link rel="chrome-webstore-item" href="https://chrome.google.com/webstore/detail/CHROME_EXTENSION_ID">
*/
yourApp.directive('chromeInstall',
[function() {
return {
link: function (scope, el, attrs) {
// NOTE: change to your chrome extension ID
var _URL = 'https://chrome.google.com/webstore/detail/CHROME_EXTENSION_ID';
function chromeFailed() {
window.location.href = _URL;
}
function finishInstall() {
console.log("Installed!");
}
el.bind('click', function(e) {
if (chrome.webstore.install) {
chrome.webstore.install(_URL, finishInstall, chromeFailed );
} else {
chromeFailed();
}
});
}
};
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment