mds*_*lup 7 google-chrome-extension
function doit() {
alert(3);
// Statement 1
// chrome.tabs.create({url:"http://www.google.com"});
// Statement 2
// chrome.tabs.update({url:"http://en.wikipedia.org"});
alert(4);
}
chrome.browserAction.onClicked.addListener(doit);
Run Code Online (Sandbox Code Playgroud)
当脚本按原样运行时,我得到3和4的JS警报.好的.
当我在语句1中发表评论并运行脚本时,我得到一个3级的JS警报,然后Google在一个新的活动选项卡中打开,然后我得到一个4级的JS警报.正如预期的那样.
当我在语句1中注释掉语句1和注释时,我得到了一个3的JS警报,就是这样.
据http://code.google.com/chrome/extensions/tabs.html#method-update,我并不需要通过tabId对象,因为它"默认为当前窗口的选择选项卡." url对象被定义为"用于导航选项卡的URL",正如我在语句1中运行chrome.tabs.create时注意到的那样.
为什么我的chrome.tabs.update语句不起作用?
您必须告诉它您要更新哪个选项卡 (tab.id)。
chrome.tabs.update(id,{url:"http://en.wikipedia.org"});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14060 次 |
| 最近记录: |