Question

I am implementing desktop notifications in a website which displays notifications when new messages arrive. I want the browser tab in which the site is open to get focus when the user clicks on the notification & I could get this worked in Chrome with the following code:

var n = new Notification('Title', {
    'body': 'Sample content.'
});

n.onclick = function (e) {
    window.focus();
};

But unfortunately, this doesn't work in Firefox. :( Could anyone tell me what I am missing here? I am testing in Chrome 31 & Firefox 26

Thanks.

Was it helpful?

Solution

In Firefox focusing window from JS is disabled due to security reasons. You have to switch flag dom.disable_window_flip to false in about:config. But by default it is disabled. The interesting moment is that in Chrome focusing window is disabled too except in response to user actions (such as click) and that's only reason why clicking on notifications works in Chrome.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top