如何实现浏览器内多个标签页之间的通信?
作者:
智多牛 | 来源:发表于
2017-01-04 17:04 被阅读0次
- 必须为两个不同的页面
- 旧数据为空或没有时,不会触发
- 两次改变的数据相同,不会触发
<!-- 页面A -->
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>更改数据</title>
</head>
<body></body>
<script>
window.addEventListener('click',function(){
localStorage.setItem("key",1);
})
</script>
</html>
<!-- 页面B -->
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>侦听数据更改</title>
</head>
<body></body>
<script>
window.addEventListener("storage",function(e){
console.log(e);
})
</script>
</html>
本文标题:如何实现浏览器内多个标签页之间的通信?
本文链接:https://www.haomeiwen.com/subject/pgaovttx.html
网友评论