简体   繁体   中英

Focusing browser tab when a value within the page reaches a specific number

I have a web page that refreshes constantly, where a span have a number that is changing (decreasing).

Is there a way using JS for example to automatically focus the browser tab containing the web page when that number reaches less than 10 so that the supervisor takes action before hitting 0 without knowing?

Thanks.

This is not possible.

There's two possible solutions.

  1. Browser extension. This will give you a lot more leeway and control.

  2. And this has become a lot more popular is to change the favicon on the page to another one that looks like an alert. And changing the title too. Playing a sound is another cue to the user that something has happened.

Hope this helps!

Depending on the browser and the user's settings, alert might take the user to the tab that opened the alert. In other browsers alert might only change the tab icon to stand out.

Firefox gives the user the option to enable this behavior with a “Allow dialogs from example.com to take you to their tab” checkbox, unchecked by default:

Firefox延迟警报示例

Chrome doesn't give the user any such option, but does mark the tab with an orange indicator:

在此处输入图片说明

在此处输入图片说明

You can test your browser's behavior by running this snippet and then switching to another tab:

 setTimeout(function() { alert('this is a delayed alert'); }, 3*1000); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM