How do I open a browser window from a desktop notification that's generated from a background page?
I have built a simple chrome开发者_如何学运维 application which has a background page that shows desktop notifications when a new article is available.
If a user clicks on the notifications when a browser window is open, then they are taken to the new article page and everything is right with the world.
If however the browser is closed when the notification is shown, then the href does not open the browser. I have also tried to capture the click and set a window.open, but that isn't working either.
As an aside, it would also be good if I could check to see if an instance of my app is already open and use that window/tab when the notification is clicked, but that's secondary to the first problem.
Any help would be great!
Thanks
Check if chrome window is open. if open the create in new tab else oepn new window.
chrome.windows.getCurrent(function(currentWindow) {
if (currentWindow != null) {
return chrome.tabs.create({
'url': url
});
} else {
return chrome.windows.create({
'url': url,
'focused': true
});
}
});
Have you tried, creating a window then tab using the Chrome API? For example:
linkDOM.addEventListener('click', function() {
chrome.windows.create({url: 'http://someurl.com'});
}, false);
I usually do the above when programmatically opening a link from extension pages.
精彩评论