JS实现刷新操作与选择iframe的方法
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<iframe src="3.php" name="p"></iframe>
<script language="javascript">
var temp = document.frames('p').document.getElementByid('idv').innerHTML='可以这样操作不喽!';
</script>
</body>
</html>
JS实现刷新iframe的方法
<iframe src="1.htm" name="ifrmname" id="ifrmid"></iframe>
方案一:用iframe的name属性定位
<input type="button" name="Button" value="Button"
onclick="document.frames('ifrmname').location.reload()">
或
<input type="button" name="Button" value="Button"
onclick="document.all.ifrmname.document.location.reload()">
方案二:用iframe的id属性定位
<input type="button" name="Button" value="Button"
onclick="ifrmid.window.location.reload()">
终极方案:当iframe的src为其它网站地址(跨域操作时)
<input type="button" name="Button" value="Button"
onclick="window.open(document.all.ifrmname.src,'ifrmname','')">
1. 打印iframe
eg. frameName.document.execCommand('print');
2. 获取iframe
eg. var ifr_window = window.frames["frameName"];
3. 获取iframe中的元素
eg1. 将iframe中id为elementId 的元素置为不显示:
var ifr_window = window.frames["frameName"];
ifr_window.elementId.style.display = 'none';
eg2. 获取iframe中id为listTable的表格
var oTable = window.frames["myFrame"].document.all.listTable;
4. 隐藏或显示表格的某列
js函数:
function setHiddenOrShowCol(oTable, iCol, type) {
for (i = 0; i < oTable.rows.length ; i++) {
oTable.rows[i].cells[iCol].style.display = type;
}
}
调用举例,将id为listTable的表格元素的第4列置为不显示:
var oTable = window.frames["myFrame"].document.all.listTable;
setHiddenOrShowCol(oTable, 3, 'none');
调用举例2,将id为listTable的表格元素的第4列置为显示:
var oTable = document.frames.myFrame.document.all.listTable;
setHiddenOrShowCol(oTable, 3, 'block');
js访问iframe(兼容ie&ff)
<iframe id=ifrm name=ifrm2 src=ifrm.htm></iframe>
<input type=button value=ie onclick=alert(document.frames[0].document.documentElement.innerText)>
<input type=button value=ie2 onclick=alert(window.frames[0].document.documentElement.innerText)>
<input type=button value=ie3 onclick=alert(document.getElementById("ifrm").contentWindow.document.documentElement.innerText)>
<input type=button value=ff onclick=alert(document.getElementById("ifrm").contentDocument.documentElement.textContent)>
<input type=button value=ff2 onclick=alert(document.getElementById("ifrm").contentWindow.document.documentElement.textContent)>
<input type=button value=ff3 onclick=alert(window.frames[0].document.documentElement.textContent)>
<input type=button value=get onclick=alert(document.getElementById("ifrm").contentWindow.document.getElementById('txt').value)>
<input type=button value=get2 onclick=alert(window.frames[0].document.getElementById('txt').value)>
<input type=button value=get3 onclick=alert(window.frames['ifrm2'].document.getElementById('txt').value)>
<input type=button value=src onclick=alert(document.getElementById('ifrm').src)>
<input type=button value=src2 onclick=alert(window.frames[0].location.href)>