chrome iframe问题
两个页面。一个嵌套另外一个
test1.html代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
function change()
{
var ofrm1 = document.getElementById("frame").document;
if(ofrm1 == undefined)
{
ofrm1 = document.getElementById("frame").contentWindow.document;
if(ofrm1 == undefined){
ofrm1 = document.getElementById("frame").contentDocument;
if(ofrm1 == undefined){
alert("fuck you!!!");
}
else{
var ch = ofrm1.getElementById("test");
}
}else{
var ff = ofrm1.getElementById("test");
alert("ff:"+ff);
}
}
else {
var ie = document.frames["frame"].document.getElementById("test");
alert("ie:"+ie);
}
}
</script>
</head>
<body>
<div id="1">hello</div>
<button onclick="change()" value="ok">ok</button>
<iframe name="frame" id="frame" src="test2.html"></iframe>
</body>
</html>
test2.html代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<div id="test" class="hello">world</div>
</body>
</html>
现在问题是IE和火狐都能正常显示,为什么到了chrome下取出的元素一直是undefined?
vasilli
12 years, 5 months ago