简体   繁体   中英

How can I access to an iframe DOM?

I just want to access to the DOM in an iframe. I can display in the Chrome console to the whole iframe definition with the code below :

$('document').ready(function(){
var toto = window.parent.$("#compare_package")[0];
console.log(toto);
});

But I don't find the solution to access to the '#document' content. I tried :

var toto = window.parent.$("#compare_package")[0].contentDocument;

or :

var toto = window.parent.$("#compare_package")[0].contentWindow;

But it does not work. Does anyone can help me ? Thanks in advance for your help.

it only works in same origin policy

// you iframe
<iframe id="some" src=""></iframe>

// bind after iframe content is loaded
$("#some").contents().find('.item');

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