Blogger Information
Blog 143
fans 1
comment 0
visits 440311
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
js跨页面触发事件,利用storage监听事件
弘德誉曦的博客
Original
1136 people have browsed it

js跨页面触发事件,利用storage监听事件

2019年03月14日 17:29:59 haohemr 阅读数 184

 版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/document_dom/article/details/88557462

同一浏览器打开了两个同源页面

其中一个网页修改了localStorage

另一网页注册了storage事件

网页A:监听了storage事件:

window.addEventListener("storage", function (e) {
       alert(e.newValue);
   });123

网页B:修改了localStorage

localStorage.setItem('foo', 'bar');1

将上面两个网页保存,放到同一个服务器上,然后,先打开A.html,再打开B.html。就会看到A.html会弹出提示框。注意两个网页要同源。


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post