Menu
JS+HTML5实现多域名本地共享数据
1.A域名,利用iframe存储数据,一般为用户登录界面
www.xx.com.cn/testhtml5store.html
<!DOCTYPE html> <html> <head> <title>HTML5存储本地信息</title> </head> <body> <iframe id="myframe" hidden src=""></iframe> HTML5存储本地信息 <script src="http://101.200.89.239/js/jquery.js"></script> <script type="text/javascript"> //添加key-value 数据到 sessionStorage var datas = "goumingqiang test save lacal data"; localStorage.setItem("demokey", datas); $("#myframe",parent.document.body).attr("src","http://cy.mmarri.com.cn/testhtml5/teststore.php?savestroge="+datas); </script> </body> </html>
2.B域名通过A域名下的页面ifreame的访问存储数据
http://www.xx.com/testhtml5/teststore.php?savestroge="+datas
 
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>save data</title> </head> <body> save data <script src="http://101.200.89.239/js/jquery.js"></script> <script type="text/javascript"> localStorage.setItem("demokey","asdasf"); //localStorage.clear(); </script> </body> </html>
3.B域名其他页面获取存储的本地数据
www.xx.cn/testhtml5/getlocaldata.html
<!DOCTYPE html> <html> <head> <title>HTML5存储本地信息</title> </head> <body> HTML5存储本地信息 <script src="101.200.89.239/js/jquery.js"></script> <script type="text/javascript"> var datas = localStorage.getItem("demokey"); alert(datas); </script> </body> </html>