CodeSky 代码之空

随手记录自己的学习过程

在 HTTP 网站中开启 Notification API

2020-09-24 22:33分类: JavaScript评论: 1

Notification API 只能在 HTTPS 中使用:Using the Notifications API

This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

但是在开发某游戏网站脚本的时候,虽然它用的是 HTTP,但是仍然想用 Notificition 做一下提醒功能,当然,可以降级成过去 800 年的闪 Title 策略:

1let shaking = false
2setInterval(() => {
3    if (shaking) document.title = `[Notification] ${word}!!`
4    else document.title = word
5    shaking = !shaking
6}, 200)
7

但是实测效果还是不够显眼,最终在和群友的交流之后,发现了 chrome://flags/

Insecure origins treated as secure 中填写需要开启 Notification API 的域名,重启浏览器,就可以在 HTTP 中使用 Notification API 了。

评论 (1)

阿冰2020年10月21日 14:59

没错,在下就是那个群友