firefox扩展;如何在新标签中打开链接

时间:2017-11-21 15:33:26

标签: javascript

如何在新标签中打开chrome.tabs.executeScript的结果?

window.addEventListener("click", whatever())
    function whatever() {
        chrome.tabs.executeScript(null, {
        code: 'window.getSelection().toString();',
        allFrames: true,
    }, function(result) {
     //open link 'https://'+result.toString() in new tab
    });
};

1 个答案:

答案 0 :(得分:0)

您可以使用带有_blank参数的window.open实现该目的:

...
}, function(result) {
  var redirectWindow = window.open('https://'+result.toString(), '_blank');
  redirectWindow.location;
 //open link 'https://'+result.toString() in new tab
});
...