js获取iframe中的内容 兼容火狐&&ie6

来源:互联网 发布:手机注册界面html源码 编辑:程序博客网 时间:2024/05/16 03:59
<!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>
<script language="JavaScript" type="text/javascript">
//显示iframe中的内容
function list(){
//alert(document.getElementById("ali").contentWindow.document.documentElement.outerHTML);
document.getElementById('content').innerHTML=document.getElementById("ali").contentWindow.document.body.innerHTML;
}
</script>

</head>

<body>
<p><a href="#" onclick="list()">点击</a></p>
<p>&nbsp; </p>
<!--只能显示同域的内容,如果访问www.163.com等不同域名的网站则不行-->
<iframe id="ali" src="f.html" width="1024" height="500"></iframe>
<div id="content"></div>
</body>

</html>