您的位置:首页 > 其它

获取 Iframe内的元素对象

2011-08-12 21:20 190 查看
//这一篇是Javascript,不是Jquery

1,实现javascript重载iframe页面,兼容各浏览器的方法

document.getElementById(FrameID).contentWindow.location.reload(true);

2,其次是获取iframe内的元素并应用

iframe.contentWindow.document.getElementById(id).style.display="block";

3,iframe页面调用父级页面中的函数

parent.dofunction();

关键字:contentWindow与parent

contentWindow 实例

iframe = document.getElementById("frame");

iframe.contentWindow.location = "http://mozilla.org";

iframe.contentWindow.history.back();

说明 http://www-archive.mozilla.org/docs/dom/domref/dom_frame_ref5.html

先整理这些,备录,继续完善。转自:http://www.liuhui.info/article16.html

获取 Iframe内的元素对象



test1.html //转自:/article/4010394.html

<html>

<head>

<script>

function t(){

var dd = document.all('test2').contentWindow.document;

dd.getElementById('my').style.display='none';

}

function getImage(paht)

{

var dd = document.all('test2').contentWindow.document;

dd.getElementById('covertImage').src=paht;

}

</script>

</head>

<body >

<input type="button" value="test" onClick="t();"/>

<input type="button" value="image1" onClick="getImage('1.jpg')"/>

<input type="button" value="image2" onClick="getImage('2.jpg')"/>

<input type="button" value="image3" onClick="getImage('3.jpg')"/>

<input type="button" value="image4" onClick="getImage('4.jpg')"/>

<iframe id="test2" name="test2" src="test2.html" frameborder="0" ></iframe>

</body>

</html>

test2.html

<html>

<head>

</head>

<body>

<div id="my" name="my">

测试一下,父窗体可以把我隐藏掉!!!!!!!!

</div>

<img src="" id="covertImage"/>

</body>

</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: