要兼容IE6,7,8的
iframe的结构,是
<iframe name="bbcode" id="bbcode" src="bbcode/bbcode.php" frameborder="0" marginheight="0" marginwidth="0" scrolling="No" style="width: 100%; height: 410px;"></iframe>然后BBCODE页面下<iframe id="contents" name="contents" frameborder="0" marginheight="0" marginwidth="0" scrolling="auto"></iframe> 给contents 赋值
iframe的结构,是
<iframe name="bbcode" id="bbcode" src="bbcode/bbcode.php" frameborder="0" marginheight="0" marginwidth="0" scrolling="No" style="width: 100%; height: 410px;"></iframe>然后BBCODE页面下<iframe id="contents" name="contents" frameborder="0" marginheight="0" marginwidth="0" scrolling="auto"></iframe> 给contents 赋值
'window.frames.contents.document' 为空或不是对象你这个不行的。
document.getElementById( "bbcode ").contentWindow.document.getElementById( "content").contentWindow.document.body.innerText="";
jieshao.php<?php include_once"ajax.php"; include_once"access_denied.php";?>
<link href="admin.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="../include/js/admin.js"></script>
<script type="text/javascript" src="../include/js/ajax.js"></script>
<div id="admin_message">
<div id="admin_message_1">
<div id="admin_right_3_1">企业介绍 </div><br />
<iframe name="bbcode" id="bbcode" src="bbcode/bbcode.php" frameborder="0" marginheight="0" marginwidth="0" scrolling="No" style="width: 100%; height: 410px;"></iframe>
<input id="news" type="button" name="" onclick="jieshao_xx()" value="保存介绍" />
</div>
<?php
$corp = $mz_mysql->mysql_give("select * from mzrui_corp");
$str = str_replace("\n", "", $corp[corp]);
$str = str_replace("\r", "", $str);
echo ("<script>window.onload = function(){corp('$str');}</script>");
?>JSfunction corp(jieshao)
{
if (navigator.appName == 'Microsoft Internet Explorer')
{
document.getElementById( "bbcode").contentDocument.getElementById( "contents").contentDocument.body.innerHTML = jieshao; }
else
{
document.getElementById( "bbcode").contentWindow.document.getElementById( "contents").contentWindow.document.body.innerHTML = jieshao; }
}然后BBCODE.PHP 就是这个 <iframe id="contents" name="contents" frameborder="0" marginheight="0" marginwidth="0" scrolling="auto"></iframe>
你的这个方式只能在firefox下用,IE 8 下不行
{
var f = window.frames["contents"];
f.document.designMode="on";
}
你的这个方式好像赋值也不行,不知道是不是页面装载没完成造成的,'document.frames(...).document.frames(...).document.body' 为空或不是对象报这个错误
<input type=button value="赋值" onclick="Add()" />
<script>
function Add()
{
window.frames["contents"].document.open();
window.frames["contents"].document.write("<body>赋值</body>")
window.frames["contents"].document.close();
}
</script>
那是因为你的iframe是空的,没有document对象的,。你这样写
<iframe src="b.htm" name="contents" b.htm写
<html>
<body>
</body>
</html>就可以了
onload执行---->iframe元素生成----->onload执行完---->iframe加载src中的页面
结果就是你取不到Iframe中src指定页面的document对象
我是新手,纯属个人理解,有不对的地方希望大神们纠正,楼主可参考
不过这个在FF下面没有问题的,就是在IE下面 会报对象为空
获取/设置IFRAME内对象元素的几种JS方法(2011
echo ("<script>window.onload = function(){corp('$str');}</script>");
你把代码写这个页面里面,而不是外面