跨域和 iFrame

发布于 2024-12-19 23:21:24 字数 402 浏览 3 评论 0原文

我正在尝试一些我真的无法弄清楚的事情。我有一个 iFrame 从另一个我无权访问的域加载一些内容。我“简单地”尝试做的是获取 iFrame 的内容以在 PHP/Javascript 中使用它。这就是我遇到的“跨域”问题。我无法访问 iFrame 的内容。太令人沮丧了。

所以我读了又读,看到了 HTML5 提供的“postMessage()”函数。我看到了这个系统的解决方案,但我仍然无法弄清楚一点。基本上,它与发送者和监听者一起工作。因此,我需要在 iframe 中有一个侦听器,当触发该侦听器时,会将内容发送回主窗口。

但是如何在已加载的 iFrame 中添加一些代码而不删除内容呢?

我真的不需要使用 postMessage(),只要我能得到这个该死的内容,我可以是任何人!

任何建议表示赞赏!

谢谢 !

I am trying to something I really can't figure out. I have an iFrame loading some content from another domain on which I have no power. What I am "simply" trying to do is fetch the content of the iFrame to use it in PHP/Javascript. This is where I faced the "cross-domain" problem. I am unable to access the content of the iFrame. So frustrating.

So I read, and read some more and seen about the "postMessage()" function provided by HTML5. I saw a solution with this system, but I still can't figure one point. Basically, it works with a sender and a listener. So I need to have a listener in the iframe that, when triggered, will send the content back to the main window.

But HOW do I add some code in the already loaded iFrame without deleting the content ?

I don't really need to use postMessage(), I can be anything as long as I can get this damn content !

Any suggestion is appreciated !

Thank you !

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一个人的旅程 2024-12-26 23:21:24

这仍然是不可能的,并且有充分的理由!

要使用客户端的 cookie、IP 和凭据从另一个域读取数据,需要查看的页面以某种方式公开信息 - 这是侦听器(外部页面)和发送器 (IFrame) 协同工作的双向对话。

需要这样做的原因是:想象一下制作一个占据 100% 页面的 IFrame。您可以在 IFrame 中显示常见网站的登录表单,但拦截击键/输入框更改并记录它们。用户只有检查 URL 才会知道其中的区别。

如果您可以控制用户的浏览器,则可以使用GreaseMonkey的跨域AJAX来获取IFrame的内容(假设Firefox / Chrome)

This is still not possible and for good reason!

To read from another domain using the client's cookies, IP and credentials requires the page being viewed to expose the information somehow - It's a 2-way conversation with the Listener (Outer page) and Sender (IFrame) working together.

A reason this is required: Imagine making an IFrame that takes up 100% of the page. You could show a common website's login form in the IFrame and yet intercept keystrokes/input box changes and log them. The user would only know the difference if they checked the URL.

If you have control over the browser of the user, you could use GreaseMonkey's cross-domain AJAX to get the contents of the IFrame (Assuming Firefox/Chrome)

淡淡の花香 2024-12-26 23:21:24

这样的事情不会有帮助吗:

function getContentFromIframe(iFrameName)
{

    var myIFrame = document.getElementById(iFrameName);
    var content = myIFrame.contentWindow.document.body.innerHTML;

    //Do whatever you need with the content    

}


Wont something like this help:

function getContentFromIframe(iFrameName)
{

    var myIFrame = document.getElementById(iFrameName);
    var content = myIFrame.contentWindow.document.body.innerHTML;

    //Do whatever you need with the content    

}


~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文