开发者

Open new tab from chrome extension

I wanna create a chrome extension that when you click it that you open my website. But how? I tried searching on google but this is all what I could create:

{
  "name": "My First Extension",
  "version": "1.0",
  "description": "The fi开发者_JAVA技巧rst extension that I made.",
  "browser_action": {
    "default_icon": "icon.png"
    chrome.tabs.create({'url': chrome.extension.getURL('popup.html')}, function(tab) {
        // Tab opened.
    });
  },
  "permissions": [
    "http://api.flickr.com/"
  ]
}

But this doesn't seem to work.


The bit of code,

chrome.tabs.create({'url': chrome.extension.getURL('popup.html')}, function(tab) {
    // Tab opened.
});

cannot be used directly in the manifest. If you look at the documentation for how to use browser actions, the correct way of handling the click event is to put something like this in the JavaScript on your background page:

chrome.browserAction.onClicked.addListener(function() {

    chrome.tabs.create({'url': chrome.extension.getURL('popup.html')}, function(tab) {
        // Tab opened.
    });

});

From your manifest, it looks like you don't have a background page. Simply create an HTML file with some JavaScript in it, and reference it in the manifest like so:

"background_page" : "background.html"


{"manifest_version": 2,"name": "my app","version": "2.0","description": "This is a chrome extension for my app","browser_action": {"default_icon": "icon.png","default_popup": "popup.html"},"permissions": ["www.bibsoblog.blogspot.com"]}

If you want create a extention to go to your website by clicking the extension, and just use this code here click this to add that code to your popup.html.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜