简体   繁体   English

iFrame从其他域上的父网址获取参数

[英]IFrame get parameters from parent url on different domain

It seems this is not possible by default because I get error blocked a frame with origin x from accessing a frame with origin y. 似乎这在默认情况下是不可能的,因为我收到错误阻止了原点为x的帧访问原点为y的帧。 I know this is because of security but I would like to allow by partners to integrate my iframe. 我知道这是出于安全原因,但我想允许合作伙伴集成我的iframe。 Iframe is on domain mysubdomain.mysite.com and contains search box. iframe位于域mysubdomain.mysite.com上,并包含搜索框。 Once user has made search it has been redirected to page partners-domain-containing-search-results.com Search results are also on domain mysubdomain.mysite.com and I would like to read parameters from url (hash and query string parameters) but I can't because I can't read parent url parameters (from partners-domain-containing-search-results.com ). 用户进行搜索后,它已被重定向到页面partners-domain- contains-search-results.com,搜索结果也位于域mysubdomain.mysite.com上,我想从url中读取参数(哈希和查询字符串参数),但是我不能,因为我无法读取父url参数(从partners-domain- contains-search-results.com)。

You should be able to use top.location from subdomain.mysite.com to read the parent urls of partners-domain-containing-search-results.com: 您应该能够使用subdomain.mysite.com中的top.location来读取partners- top.location的父URL:

eg from an iframe hosted on mysubdomain.mysite.com and embedded in partners-domain-containing-search-results.com?hello=true#blabla you should be able to run: 例如,从托管在mysubdomain.mysite.com上并嵌入在partners-domain- contains-search-results.com中的iframe中?hello = true#blabla,您应该可以运行:

top.location.hash
>"#blabla"
top.location.search
>"?hello=true"

Note: you cannot modify the other domain's location object or you will see: 注意:您无法修改其他域的位置对象,否则您将看到:

Uncaught SecurityError: Blocked a frame with origin " http://domain2.com " from accessing a frame with origin " http://domain.com ". 未捕获的SecurityError:被阻止与原籍“帧http://domain2.com访问的帧与原籍”“ http://domain.com ”。 Protocols, domains, and ports must match. 协议,域和端口必须匹配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM