開新分頁,則透過create方法去建立一個新分頁即可,但注意當開啟的分頁不是這個Extensions內的檔案,則需要在Manifest新增url到permissions
執行結果:
index.html:
<!DOCTYPE html> <html> <head> <title>:)</title> </head> <body> <h1>Hi</h1> </body> </html>
test.js:
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.create({"url": "http://yahoo.com.tw"});
});
Manifest:
{
"name": "C.Y. Fang",
"manifest_version": 2,
"version": "0.0.1",
"description": "Happy new year",
"homepage_url" : "http://cyfangnotepad.blogspot.tw/",
"icons": {
"16" : "Images/book16.png",
"128": "Images/book128.png"
},
"browser_action": {
"default_title": "Title",
"default_icon": "Images/book16.png"
},
"background": {
"scripts": ["test.js"]
},
"permissions": [
"tabs",
"http://yahoo.com.tw/*"
]
}
