Monday, June 3, 2024
54
rated 0 times [  58] [ 4]  / answers: 1 / hits: 19984  / 10 Years ago, thu, november 13, 2014, 12:00:00

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?


More From » google-chrome-app

 Answers
62

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);
});

[#68811] Tuesday, November 11, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jarrodfletchers

Total Points: 75
Total Questions: 94
Total Answers: 95

Location: Netherlands
Member since Thu, Jul 1, 2021
3 Years ago
jarrodfletchers questions
Sat, Sep 25, 21, 00:00, 3 Years ago
Mon, Jan 21, 19, 00:00, 5 Years ago
Sun, Dec 16, 18, 00:00, 6 Years ago
Sun, Nov 4, 18, 00:00, 6 Years ago
;