4
當iframe源位於不同的域時,是否可以使用jQuery來訪問iframe的內容?我不想修改內容,只需在iframe完成時在html中閱讀,這就是爲什麼我不確定這是否屬於Same Origin Policy。jQuery iframe內容跨域
例如:
<script type="text/javascript" language="javascript">
$(document).ready(function() {
$("#helper").append("<iframe src='http://www.citizensbank.com' ></iframe>");
getContents("#helper");
});
function getContents(iframeID) {
if ($(iframeID + " iframe").context.readyState != "complete") {
setTimeout("getContents('" + iframeID + "');", 200);
} else {
alert($(iframeID + " iframe").contents().html());
}
}
</script>
<div id="helper"><iframe src="http://www.example-B"></iframe></div>
是的,這屬於同源政策。 – gradbot