The window object does not have the properties attached to it by the page that created it

拥有回忆 提交于 2019-12-06 07:32:10

Use window.opener, SharedWorker with postMessage or storage event

Page1.html

<script>
  function openNewPage(value1, value2) {
    var newWindow = window.open('Page2.html', '_blank')

    this.property1 = value1;
    this.property2 = value2;
  }
  openNewPage(1, 2)
</script>

Page2.html

<body onload="bodyLoadHandler()">
  <script type="text/javascript">
    function bodyLoadHandler() {
      var property1 = window.opener.property1;
      var property2 = window.opener.property2;
      console.log(property1, property2);
    }
  </script>
</body>

plnkr http://plnkr.co/edit/Gy5FFhvobFoBAbc8UnBY?p=preview

See also How can I load a shared web worker with a user-script?, Can the mechanism that loads the worker in Shared Web Workers be modified?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!