6

How do I make it that when I click my extension button in the upper right, it redirects me to another page? My manifest looks a little something like this.

{
  // Extension Info
  "manifest_version": 2,
  "name": "Extension",
  "version": "0.0.1",
  "description": "Text",

  // Action
  "browser_action": {
    "default_icon": "icon_64.png",
    "default_popup": "popup.htm"
   },

  // Other decorative stuff
  "icons": {
      "128": "icon_128.png",
      "64": "icon_64.png",
      "16": "icon_16.png"
   }
}

And popup looks like this

<!DOCTYPE html>
<html>
    <head>
        <script type="text/javascript">
            window.open("http://website.com",'_blank');
        </script>
    </head>
    <body>
        <h1>Redirecting...</h1>
    </body>
</html>

Any Ideas? Thanks! -SensiAking1

a4x
  • 180
  • 9

1 Answers1

2

In background script, implement an onclick handler for browserAction button as follows.

chrome.browserAction.onClicked.addListener(function (tab) {
  chrome.tabs.update({ url: "http://website.com" });
});
Nandu
  • 808
  • 7
  • 10
  • 1
    This is actually a correct alternative solution, but something else needs to be said, since there is no background script in the reference code yet, and it won't work when a popup is defined. – Xan Nov 07 '15 at 09:29
  • Xan: I actually had a background script `"background": "bgredirect.htm",`, but thought it was irrelevant so didn't include it. My bad. So solution was to make the JS not inline and to put it in a seperate JS file. Thanks! – a4x Nov 07 '15 at 10:47
  • if this answer worked for you, please accept the answer – Nandu Nov 07 '15 at 16:23