Saurabh Saxena
Saurabh Saxena

Reputation: 3215

Chrome Extension Not Working

I have used the following code to open the current page URL in Rich Snippet Testing Tool. The problem is this that the extension works fine on first click and open the URL. But if the Testing page URL is currently open it will not allow to open another one.

My requirement is to open several pages at a time in Testing Tool with the help of this extension. But i am able to open only one at a time.

My Manifest File:

{
  "name": "RS Analyzer",
  "description": "Extension to get current page URL and display its Rich Snippets.",
  "version": "1.4",
  "background_page": "background.html",
  "permissions": [
    "tabs", "http://*/*", "https://*/*"
  ],
  "icons":{"16": "images/R_icon_16x16.jpeg",
           "48": "images/R_icon_48x48.jpeg",
          "128": "images/R_icon_128x128.jpeg"},
  "browser_action": {
      "default_title": "RS Analyzer",
      "default_icon": "images/icon.jpg"
  }
}

My Background Page:

chrome.browserAction.onClicked.addListener(function(tab){
    chrome.tabs.getSelected(null,function(tab) {
    var tablink = tab.url;
    var richurl = "http://www.google.com/webmasters/tools/richsnippets?url=" + encodeURIComponent(tablink) + "&view=";
    window.open(richurl,'_newtab');
    });
  });

Upvotes: 0

Views: 256

Answers (2)

Lycha
Lycha

Reputation: 10187

Chrome doesn't understand "_newtab", it only considers it as an id for the tab so it will open the next one to the same tab. Using "_blank" will normally open new tab but it depends on user's settings (it may also open new window).

If you want new tab you should probably look into Chrome Extension tabs api. They have a create method there. It'll require you to set the permissions for the extension.

Upvotes: 1

pimvdb
pimvdb

Reputation: 154968

It's because you gave the window (tab) a name. This means that the same tab is used each time. It's like an identifier of the tab.

You can solve this by removing the name:

window.open(richurl);

Upvotes: 1

Related Questions