简体   繁体   中英

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. Currently I do that via the jQuery call $("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.

Is there a way for me to reliably check the contents of an iframe? I only need to know about the existence of a password element, not to interact with it in any way.

Use window.postMessage

Code sample...

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

Code for 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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