gpt4 book ai didi

javascript - 使用 JavaScript 在浏览器选项卡/窗口之间进行通信

转载 作者:行者123 更新时间:2023-11-28 05:17:22 26 4
gpt4 key购买 nike

让 JavaScript 在同一浏览器的选项卡/窗口之间进行通信的最可靠方法是什么?例如,当选项卡 2 开始音频播放时,选项卡 1 会以某种方式知道这一点并可以暂停其播放器。

我正在构建一个带有音乐播放器的网站...因此,目前如果您打开该网站的两个选项卡,则可以在两个选项卡上开始播放音乐。这显然很糟糕,所以我正在努力寻找解决方案。

最佳答案

要获得更现代的解决方案,请查看 https://stackoverflow.com/a/12514384/270274

引用:

I'm sticking to the shared local data solution mentioned in the question using localStorage. It seems to be the best solution in terms of reliability, performance, and browser compatibility.

localStorage is implemented in all modern browsers.

The storage event fires when other tabs makes changes to localStorage. This is quite handy for communication purposes.

Reference:
http://dev.w3.org/html5/webstorage/
http://dev.w3.org/html5/webstorage/#the-storage-event

关于javascript - 使用 JavaScript 在浏览器选项卡/窗口之间进行通信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40862735/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com