localStorage跨域问题

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq1036548849/article/details/85245852
  • 域名1:
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <title>a.html</title>
  </head>
  <body>
    <iframe style='display:none'  src="域名2"></iframe>
    <script type="text/javascript">
      window.onload = function () {
        window.frames[0].postMessage('信息','域名2');
      }
    </script>
  </body>
</html>
  • 域名2:
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <title>a.html</title>
  </head>
  <body>
    <script type="text/javascript">
      window.addEventListener('message', function (e) {
        if (e.source == window.parent){console.log(e)}
      }, false);
    </script>
  </body>
</html>

猜你喜欢

转载自blog.csdn.net/qq1036548849/article/details/85245852