Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

原生js 如何实现跨页面通信? #16

Open
JslinSir opened this issue Jun 20, 2022 · 0 comments
Open

原生js 如何实现跨页面通信? #16

JslinSir opened this issue Jun 20, 2022 · 0 comments
Labels
奇巧淫技 开发中遇到的一些奇巧淫技

Comments

@JslinSir
Copy link
Owner

实现原理,监听 storage

 // 监听 storage 变化
          window.addEventListener('storage',   (e)=>{
            console.log('e:',e)
            if (e.key === 'xxxx') {
                const params = JSON.parse(e.newValue);
         
            }
        });

触发 storage,这里必须 window.localStorage.setItem 才生效

   window.localStorage.setItem('xxxx',JSON.stringify({
               name:'1111',
              age:'18'
            }))
@JslinSir JslinSir added the 奇巧淫技 开发中遇到的一些奇巧淫技 label Jun 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
奇巧淫技 开发中遇到的一些奇巧淫技
Projects
None yet
Development

No branches or pull requests

1 participant