我这里没问题,2.0的.
是不是你标签重复了,标记没放对
<html>
<head>
</head>
<body>
<script type="text/javascript">
document.write(' <html> <body> <td> <iframe id="test" name="test" frameborder="0" scrolling="no" style="width:500px;height:500px;overflow:hidden"> </iframe>');
var randomValue = Math.random();
var code1 = "netease <iframe src='http://images.163.com/homepage/logo.gif' frameborder=0 scrolling='no' width=468 height=200> </iframe>";
var code2 = "sina <iframe src='http://i2.sinaimg.cn/home/07index/sinahome_ws_009.gif' scrolling='no' frameborder=0 width=468 height=200> </iframe>";
window.frames["test"].document.write(randomValue >= 0.5 ? code1 : code2);
</script>
</body>
</html>
是不是你标签重复了,标记没放对
<html>
<head>
</head>
<body>
<script type="text/javascript">
document.write(' <html> <body> <td> <iframe id="test" name="test" frameborder="0" scrolling="no" style="width:500px;height:500px;overflow:hidden"> </iframe>');
var randomValue = Math.random();
var code1 = "netease <iframe src='http://images.163.com/homepage/logo.gif' frameborder=0 scrolling='no' width=468 height=200> </iframe>";
var code2 = "sina <iframe src='http://i2.sinaimg.cn/home/07index/sinahome_ws_009.gif' scrolling='no' frameborder=0 width=468 height=200> </iframe>";
window.frames["test"].document.write(randomValue >= 0.5 ? code1 : code2);
</script>
</body>
</html>
<body>
<script type="text/javascript">
document.write('<iframe name="test1" frameborder="1" style="width:500px;height:500px;"></iframe>');
var randomValue = Math.random();
var code1 = "netease <iframe name='x' src='' width=468 height=200></iframe>";
var code2 = "Google <iframe name='x' src='' width=468 height=100></iframe>";
var img1="http://images.163.com/homepage/logo.gif"
var img2="http://www.google.cn/intl/zh-CN/images/logo_cn.gif"
window.frames["test1"].document.write(randomValue >= 0.5 ? code1 : code2);
window.frames["test1"].frames[0].location.href= randomValue >= 0.5 ? img1 : img2 </script>
</body>
</html>
<html>
<head>
<script type="text/javascript">
document.write(' <html> <body> <td> <iframe id="test" name="test" frameborder="0" scrolling="no" style="width:500px;height:500px;overflow:hidden"> </iframe>');
var randomValue = Math.random();
var code1 = "netease <iframe src='http://images.163.com/homepage/logo.gif' frameborder=0 scrolling='no' width=468 height=200> </iframe>";
var code2 = "sina <iframe src='http://i2.sinaimg.cn/home/07index/sinahome_ws_009.gif' scrolling='no' frameborder=0 width=468 height=200> </iframe>";
window.frames["test"].document.write(randomValue >= 0.5 ? code1 : code2);
//在这里加入弹出代码,看到代码是没有问题的。
alert(window.frames["test"].document.body.innerHTML)
</script>
</head>
</html>
谢谢net_lover,你的做法虽然能避免产生我提到的bug,但在实际项目中不可行。因为 code1,code2是一段完整的的code(甚至是一段javascript code),我们无法从这段代码中抽出image的url,即使能,这种方法也不太可取。大家觉得这是firefox的bug吗?
呵呵,大家还有其他好的解决方法吗?如果没有好的解决方法,我就当是firefox的一个bug,报给firefox的开发社区了,让他们去fix了。