Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Activate browser tab using HTML5 Notification

I'm using the HTML5 Notification API to show a message if new content is available. I'd like to show the browser tab that caused the notification to be activated when the user clicks the message, but I haven't been able to find an API to do so. I did find the Page Visibility API, but it only seems to send events when tabs change, not allow me to activate a tab.

Is it possible to control the browser like this, or is it simply not allowed?

like image 516
Jorn Avatar asked Feb 09 '23 04:02

Jorn


1 Answers

If anything, window.focus() should do it from inside the notification's click event handler.

See https://notifications.spec.whatwg.org/#activating-a-notification for details.

like image 194
Anne Avatar answered Feb 11 '23 23:02

Anne