我想将 url 传递给外部程序(使用程序打开 url),但不创建新选项卡/窗口。我使用“chrome.contextMenus.create”使用程序打开网址:右键单击链接并“使用外部程序打开”:http://postimg.org/image/usj1yb8gj/
我为我的 chrome 扩展编写了下一个代码:
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 与特定程序关联时)可以打开而不创建新选项卡吗?
最佳答案
天啊。我只需要将 create
替换为 update
- chrome.tabs.update({...});
关于javascript - 使用 URI 方案打开外部程序,无需创建新选项卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31280476/