从iframe访问父网址 [英] Access parent URL from iframe
问题描述
好吧,我在这个网页上有一个网页,我有一个iframe。我需要做的是在iframe页面上,找出主页的URL。
Okay, I have a page on and on this page I have an iframe. What I need to do is on the iframe page, find out what the URL of the main page is.
我已经搜索过,我知道如果我的iframe页面在不同的域,这是不可能的,因为这是跨站点脚本。但是我读过的每一个地方都说,如果iframe页面与父页面在同一个域,它应该工作,如果我做例如:
I have searched around and I know that this is not possible if my iframe page is on a different domain, as that is cross-site scripting. But everywhere I've read says that if the iframe page is on the same domain as the parent page, it should work if I do for instance:
parent.document.location
parent.window.document.location
parent.window.location
parent.document.location.href
...其他类似的组合,因为似乎有多种方式获得相同的信息。
... or other similar combos, as there seems to be multiple ways to get the same info.
无论如何,这里有问题。我的iframe与主页位于同一个域,但它不在同一个SUB域上。例如,我有
Anyways, so here's the problem. My iframe is on the same domain as the main page, but it is not on the same SUB domain. So for instance I have
http:// www.mysite.com/pageA.html
http:// www.mysite.com/pageA.html
,然后我的iframe网址为
and then my iframe URL is
http:// qa-www.mysite .com / pageB.html
http:// qa-www.mysite.com/pageB.html
当我尝试从 pageB.html
(iframe页面),我不断得到相同的拒绝访问错误。所以看来,即使子域计算为跨站点脚本,是正确的,还是我做错了什么?
When I try to grab the URL from pageB.html
(the iframe page), I keep getting the same access denied error. So it appears that even sub-domains count as cross-site scripting, is that correct, or am I doing something wrong?
推荐答案
你是对的。当使用iframe时,子域仍被视为单独的域,因此,iframe和主页不能互相交互。 (更新:可能,见其他答案)
You're correct. Subdomains are still considered separate domains when using iframes, so you, the iframe and the main page can never interact with each other. (update: may be possible, see other answers)
这篇关于从iframe访问父网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!