- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当收到新消息时,我在项目中使用BroadcastChannel更改所有选项卡的标题。
问题在于它仅适用于chrome和firefox。因此,我决定使用localStorage创建一个BroadcastChannel:
setInterval(function() {
// check new messages:
var title = localStorage.getItem('title');
if(title != null && title != 0){
document.title = document.title.replace(/\(\d+\)\s+/, "");
document.title='('+title+')' + " " + document.title;
}
localStorage.setItem("title", "0");
}, 100);
localStorage.setItem("title", i);
最佳答案
不要使用间隔读取本地存储,而应使用每次调用setItem时都会触发的“存储”事件。
对于真正适用于所有浏览器的BroadcastChannel,我建议https://github.com/pubkey/broadcast-channel
关于javascript - 具有localStorage的BroadcastChannel-兼容性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51085310/
我的网页有 var bc = new BroadcastChannel('Consumer'); bc.onmessage = function(event) { alert("a"); } bc
我正在测试 BroadcastChannel功能,我遇到了麻烦。我打开两个 Chrome 窗口和每个窗口的开发工具。在我写的控制台上: const z = new BroadcastChannel('
有没有办法使用 Chrome DevTools 来查看 BroadcastChannel 中发生了什么?除了附上 message它的事件监听器,这样我就可以看到谁是 postMessage - 什么?
我能够成功从我的服务器获取推送通知并用此更新 react 组件 self.addEventListener('push', event => { const data = event
问题: 我需要一个客户端 Javascript 解决方案(jQuery 很好),其中一个浏览器窗口/选项卡中的事件可以广播到同一域中的其他窗口/选项卡。例如,如果购物车在选项卡 A 中更新,选项卡 B
我是一名优秀的程序员,十分优秀!