0
其他iframe
中有一个iframe
iframe
。我想从第二个iframe
获得浏览器的URL (例如:http://test)。从两级深度iframe中获取浏览器网址
//browser URL: http://test <-- I need this URL
<iframe src="http://level1">
<iframe src="http://level2">
<!-- some content -->
</iframe>
</iframe>
我试图document.referrer
但它给后面的第一个iframe的网址:
<iframe src="http://level1">
<iframe src="http://level2">
console.log(document.referrer); //It gives back http://level1
</iframe>
</iframe>
UPDATE:
的top.location.href
不起作用,因为有不同的域。不同的浏览器,第一个和第二个iframe域。 (我们的网站 - 广告服务器 - 第三方网站)
如果所有页面共享相同的域名,您可以在任何'iframe'中获得最顶层窗口的URL,如下所示:'top.location.href'。 – Teemu
有两个不同的域。我收到错误消息:'Uncaught SecurityError:阻止了一个来自“http://www.firsturl.com”的框架访问源于“http://secondurl.com”的框架。协议,域和端口必须匹配。“ – kotapeter
嗯,猜猜你运气不好。同源政策不会允许你这样做。 – epascarello