从iframe访问父URL好的,我有一页,在这一页上我有一个iframe。我需要做的是在iframe页面上,找出主页面的URL是什么。我已经搜索过了,我知道如果我的iframe页面位于不同的域,这是不可能的,因为这是跨站点脚本。但是我所读到的任何地方都说,如果iframe页面与父页位于同一个域上,那么如果我这样做,它就会工作:parent.document.locationparent.window.document.locationparent.window.locationparent.document.location.href..或其他类似的组合,因为似乎有多种方法来获取相同的信息。不管怎样,这就是问题所在。我的iframe和主页面在同一个域上,但是它不在同一个子域上。所以,举个例子http:/www.mysite.com/pageA.html然后我的iframe URL是http:/qa-www.mysite.com/pageB.html当我试图从pageB.html(iframe页面),我一直收到相同的访问拒绝错误。所以看起来,即使是子域也算作跨站点脚本,是这样吗,还是我做错了什么?
3 回答
料青山看我应如是
TA贡献1772条经验 获得超8个赞
postMessage(...)
holdtom
TA贡献1805条经验 获得超10个赞
var url = (window.location != window.parent.location) ? document.referrer : document.location.href;
注:
window.parent.locationhrefwindow.parent.location.href
document.referreriframe
容器iframe@Domain 1 向域2发送子iframe 但在孩子身上。域2重定向到域3(即身份验证,可能是SAML),然后域3指示 背
到域2(即通过表单提交(),一种标准的SAML技术) 对孩子来说 document.referrer将是域 3
,而不是包含域。 1
document.locationwindow.location === window.parent.locationhrefhref.
添加回答
举报
0/150
提交
取消
