【问题标题】:How to know the url of opener in cross domain如何知道跨域opener的url
【发布时间】:2016-09-09 17:43:28
【问题描述】:

我有两个页面,具有不同的域。

我想从子页面知道开启页面的 url。但我无法通过 opener.location 进行操作。

例如。

Page1.html:

<html>
<head></head>
<body>
<script>
var handle = window.open("somedomain/Page2.html");
</script>
</body>
</html>

Page2.html

<html>
<head></head>
<body>
<script>
alert(opener.location) //this is not working.
</script>
</body>
</html>

【问题讨论】:

    标签: javascript cross-domain


    【解决方案1】:

    我认为您可以使用#hash 来传递开启者网址。

    Page1.html var handle =window.open("somedomain/Page2.html#opener="+encodeURI(window.location.url)); Page2.html

    var opener = decodeURI(window.location.hash.indexOf("=")[1]);

    【讨论】:

      【解决方案2】:

      尝试传递window.opener.location 否则您的应用将不知道您的opener 对象

      【讨论】:

      • 浏览器会在window.搜索任何全局变量。
      猜你喜欢
      • 1970-01-01
      • 2014-09-03
      • 1970-01-01
      • 2013-02-01
      • 1970-01-01
      • 2014-11-25
      • 1970-01-01
      • 2011-04-28
      • 2019-08-15
      相关资源
      最近更新 更多