How to open a link in chrome browser, even though the default computer browser is 'Safari'?

删除回忆录丶 提交于 2019-11-30 19:45:44

问题


I've built a chrome packaged app, and I'm trying to make one of the buttons in it open the chrome browser in a specific link.

For this, I used window.open("http://myLink.com"), which works, but unfortunately it opens the default browser rather than chrome. Is there a way around this?


回答1:


This only happens from inside the app window.

If you call window.open from the background page, it will open in Chrome.

So, send it to your background page:

// app window
function openInChrome(url) {
  chrome.runtime.sendMessage({action: "openURL", url: url});
}

// background
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
  if(message.action == "openURL") window.open(message.url);
});



回答2:


Use chrome.browser.openTab. See issue. At the moment it's in dev channel.



来源:https://stackoverflow.com/questions/26918255/how-to-open-a-link-in-chrome-browser-even-though-the-default-computer-browser-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!