问题
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