简体   繁体   English

检查iframe的内容

[英]Checking the contents of an iframe

I am working on a Chrome extension that helps me remember my passwords for websites, and it needs to detect web pages that are used for login. 我正在使用一个Chrome扩展程序,该程序可以帮助我记住我的网站密码,并且需要检测用于登录的网页。 Currently I do that via the jQuery call $("input:password") . 目前,我是通过jQuery调用$("input:password") However, I ran into a website that has the login form inside an iframe, and attempting to call $("iframe").contents() resulted in an error due to cross-origin security. 但是,我遇到了一个在iframe中具有登录表单的网站,由于跨域安全性,尝试调用$("iframe").contents()导致错误。

Is there a way for me to reliably check the contents of an iframe? 有没有办法让我可靠地检查iframe的内容? I only need to know about the existence of a password element, not to interact with it in any way. 我只需要知道密码元素的存在,而无需以任何方式与之交互。

Use window.postMessage 使用window.postMessage

Code sample... 代码示例...

otherWindow.postMessage(message, targetOrigin, [transfer]);

Code for receiveMessage receiveMessage的代码

window.addEventListener("message", receiveMessage, false);

function receiveMessage(event){
   if (event.origin !== "http://example.org:8080")
   return;
   // ...
}

Well, as far as I can tell, it's literally impossible for JS code to do this. 好吧,据我所知,JS代码实际上不可能做到这一点。

My solution: a PHP component on my server that checks the iframes' source URLs and collects a list of ones that contain a login form. 我的解决方案:服务器上的PHP组件,用于检查iframe的源URL并收集包含登录表单的URL列表。

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

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