JQ&&JS获取并操作iframe内容
获取iframe的document:
function iframeDom(id) {
return document.getElementById(id).contentDocument||document.frames[id].document;
}
jquery:
window.onload = function () {
var doc = iframeDom("my_iframe");
$(doc).find("#content").css("color","blue");
}
javascript:
window.onload = function () {
var doc = iframeDom("my_iframe");
doc.getElementById("content").style.color="blue";
}
index.html:
<iframe id="my_iframe" src="iframe.html"></iframe>
my_iframe.html:
<h1 id="content" style="color:red;">内容</h1>
注:
iframe刷新:
doc.location.reload();