0

I currently have the code below. This, however, always redirects to google. I don't get why though.

HTML

<script>
function load(){
    if (typeof extension == 'undefined') {
        window.location.href = "http://www.google.com/";
        return false;
    }
}
</script>
<body onload="load()">

inject.js from the extension

(function () {
 var extension = 11;
}());
  • possible duplicate of [Check whether user has a Chrome extension installed](http://stackoverflow.com/questions/6293498/check-whether-user-has-a-chrome-extension-installed) – Jeffrey Yasskin Mar 09 '14 at 23:16

1 Answers1

0

Javascript in a content script runs in an isolated world, in which it can't directly affect javascript running in the main page. However, you can communicate through the page's DOM, including with window.postMessage. You might create a DOM node with a known value in order to signal that the extension is running.

You'll also need to set content_scripts.run_at to either 'document_start' or document_end in order to guarantee that the content script runs before the document's onload event where you're checking that the extension exists.

Jeffrey Yasskin
  • 5,171
  • 2
  • 27
  • 39