我想将url传递给外部程序(用程序打开url ),但不创建新的选项卡/窗口。我使用"chrome.contextMenus.create“打开程序的url :右键单击链接&”打开与外部程序“:http://postimg.org/image/usj1yb8gj/
我为我的铬扩展名编写了下一个代码:
chrome.runtime.onInstalled.addListener(function() {
chrome.contextMenus.create({
title: 'Open with some program',
id: 'nameOfprogram',
contexts: ['link'],
});
});
chrome.contextMenus.onClicked.addListener(function(info, tab) {
if (info.menuItemId === "nameOfprogram") {
//var win = window.open("NameOfUriScheme://" + info.linkUrl, '_blank'); // '_self' - doesn't work...
chrome.tabs.create({ url: "NameOfUriScheme://" + info.linkUrl },function(tab){setTimeout(function(){chrome.tabs.remove(tab.id);}, 1000);});
}
});但它会打开新选项卡1秒来打开url。可以是uri-scheme:adress (当uri与特定程序相关联时),打开而不用创建新选项卡,当您使用上下文菜单打开它时
发布于 2015-07-08 00:01:19
天哪。我只需要将create替换为update - chrome.tabs.update({...});
https://stackoverflow.com/questions/31280476
复制相似问题