纯前端,html页面间传值方式:

纯前端,html页面间传值方式:


1、使用window.location的href属性,等于重新刷新页面,必须是get请求,post请求需要服务端解析,post是用来客户端服务端传递数据
window.location.href=”b.html?valus=parm”; 传值端
window.location.search; 接收端

2、 cookie ,window.localStorage(需要考虑兼容),利用浏览器存储传值,页面需要同源,不能在不同的浏览器之间如此(也即页面不能分享)。

3、通过URL中传标示,从应用的缓存中传值。和方式1类似,值不会暴露在URL中。

4、设置窗口之间的父子关联关系

5、window.postMessage 传值,HTML5新特性,需考虑兼容

猜你喜欢

转载自www.cnblogs.com/hengwu/p/9970285.html