Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get focus to the tab when a desktop notification is clicked in Firefox?

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.

like image 560
Xmindz Avatar asked Jan 09 '14 10:01

Xmindz


People also ask

How do I change Firefox notification settings?

Go to the browser menu and select "Settings." On the left, click on "Privacy & Security." Scroll down to the "Permissions" window, and select "Notification." If you want to disable notifications, check "Pause notifications until Firefox restarts." Thus, notifications will not appear until you restart Firefox.

How do I enable push notifications on Firefox?

Android or iOS: Select Menu > Settings > Notifications. Toggle Product and feature tips on or off to enable or disable notifications.

How do I turn off push notifications for Firefox?

Website notifications appear the same on Android devices. To block Firefox notifications on your smartphone, go to the browser menu. Next to 'Product and feature tips', turn the toggle switch to 'Off'.


1 Answers

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.

like image 72
Roman Bekkiev Avatar answered Oct 05 '22 10:10

Roman Bekkiev