1

我想将 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 与特定程序关联时)?

4

1 回答 1

1

我的天啊。我只需要替换createupdate-chrome.tabs.update({...});

于 2015-07-08T00:01:19.387 回答