使用 iFrame 跨域 Javascript 调用
我想要跨域 javascript 调用。
1: SiteA: www.sub1.foo.com
2: 从 SiteA 在 iframe 中打开 SiteB: www.bar.com
3: 在 SiteB 中执行某些操作后,通过 javascript 将一些值从 SiteB 传递到 SiteA。
尝试 1: 我按照这篇文章进行操作,并按照#2进行设置。但我不断收到错误:
IE: Invalid Argument
FF:Illegal document.domain value。
尝试 2: 遵循了这篇文章。
它在 FF 中有效。我可以使用 window.parent.parent.MyFunction() 但在 IE 中我收到“权限被拒绝”错误。
尝试 3: 我什至尝试了 window.postMessage 技术,但我什至无法使其工作。
有谁已经成功实现了针对上述情况的跨域 JS 调用。 或任何帮助/链接/建议。
I want to have cross domain javascript call.
1: SiteA: www.sub1.foo.com
2: Open SiteB: www.bar.com in iframe from SiteA
3: Pass some value from SiteB to SiteA via javascript after some action in SiteB.
Try 1:
I followed this article and I followed #2 for my setup. But I keep getting errors:
IE: Invalid Argument
FF:Illegal document.domain value.
Try 2:
Followed this article.
It works in FF. I can use window.parent.parent.MyFunction() but in IE I get "Permission Denied" error.
Try 3:
I even tried the window.postMessage technique but I am not even able to get that working.
Is anyone out there who has successfully implemented Cross Domain JS calls for situation like above.
Or any help / links / suggestions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以实现 window.postMessage 来跨域的 iframe/windows 进行通信。
儿童.htm
You can implement window.postMessage to communicate accross iframes/windows across domains.
Child.htm
我相信这是出于安全原因而受到限制。
之前在 Stack Overflow 上已经讨论过:
I believe this is restricted for security reasons.
It's been discussed previously on Stack Overflow here: <iframe> javascript access parent DOM across domains?
我做了这样的事情:http://blog.johnmckerrell。 com/2006/10/22/resizing-iframes-across-domains/
前段时间:)
I did something like this: http://blog.johnmckerrell.com/2006/10/22/resizing-iframes-across-domains/
some time ago :)