问题出在你的write上了,主要就是src的位置
<html>
<head>
<title>iframe test</title>
<script language='javascript'>
function init_iframe(){
document.write("<html><head><title>the_title_of_iframe_document"
+ "</title></head><body><div id='the_div'><font color='blue'>blue_blue"
+ "</font></div><input name='the_inp' type='text' value='input_0' />"
+ "<input name='the_inp' type='text' value='input_1' />"
+ "<input name='the_inp' type='text' value='input_2' />"
+ ""
+ "</body></html>"
);
}
</script>
</head>
<body>
<iframe name='the_iframe' id='the_iframe' >
</iframe> <!-- --><!--
<iframe name='the_iframe' id='the_iframe' src="test1.html" >
</iframe> -->
<SCRIPT LANGUAGE="JavaScript" defer>
window.frames["the_iframe"].open();
window.frames["the_iframe"].document.write('<html><head><title>the_title_of_iframe_document'+ '</title></head><body><div id=\'the_div\'><font color=\'blue\'>blue_blue' + '</font></div><input name=\'the_inp\' type=\'text\' value=\'input_0\' />' + '<input name=\'the_inp\' type=\'text\' value=\'input_1\' />' + '<input name=\'the_inp\' type=\'text\' value=\'input_2\' /></body></html>');
window.frames["the_iframe"].close();
alert(document.getElementById('the_iframe').contentWindow.document.title)
alert(document.getElementById('the_iframe').contentWindow.document.documentElement.innerHTML)
alert('1. '+(window.frames['the_iframe'].document == document.getElementById('the_iframe').contentWindow.document)); //true
alert('2. '+(document.getElementById('the_iframe').contentWindow == window.frames['the_iframe'])); //true
alert('3. '+(document.getElementById('the_iframe') == window.frames['the_iframe'])); //false
alert('num of input == '+ document.getElementById("the_iframe").contentWindow.document.getElementsByTagName('input').length);
alert('div.innerHTML == '+ document.getElementById("the_iframe").contentWindow.document.getElementById('the_div').innerHTML);
alert('second input == '+ document.getElementById("the_iframe").contentWindow.document.getElementsByTagName('input')[1].value);
//求助, 以上各句在IE上都能正确执行, 但是到了火狐和Netscape上 头两句 和最后三句 都不能正确执行!!!, 求助!!!!
// 求各位高手帮小弟写出规范的能再Netscape和火狐上都能取得 iframe文档中的 input的各个值 和 id为the_div的div标签里的innerHTML的javascript语句
</SCRIPT>
</body>
</html>
<html>
<head>
<title>iframe test</title>
<script language='javascript'>
function init_iframe(){
document.write("<html><head><title>the_title_of_iframe_document"
+ "</title></head><body><div id='the_div'><font color='blue'>blue_blue"
+ "</font></div><input name='the_inp' type='text' value='input_0' />"
+ "<input name='the_inp' type='text' value='input_1' />"
+ "<input name='the_inp' type='text' value='input_2' />"
+ ""
+ "</body></html>"
);
}
</script>
</head>
<body>
<iframe name='the_iframe' id='the_iframe' >
</iframe> <!-- --><!--
<iframe name='the_iframe' id='the_iframe' src="test1.html" >
</iframe> -->
<SCRIPT LANGUAGE="JavaScript" defer>
window.frames["the_iframe"].open();
window.frames["the_iframe"].document.write('<html><head><title>the_title_of_iframe_document'+ '</title></head><body><div id=\'the_div\'><font color=\'blue\'>blue_blue' + '</font></div><input name=\'the_inp\' type=\'text\' value=\'input_0\' />' + '<input name=\'the_inp\' type=\'text\' value=\'input_1\' />' + '<input name=\'the_inp\' type=\'text\' value=\'input_2\' /></body></html>');
window.frames["the_iframe"].close();
alert(document.getElementById('the_iframe').contentWindow.document.title)
alert(document.getElementById('the_iframe').contentWindow.document.documentElement.innerHTML)
alert('1. '+(window.frames['the_iframe'].document == document.getElementById('the_iframe').contentWindow.document)); //true
alert('2. '+(document.getElementById('the_iframe').contentWindow == window.frames['the_iframe'])); //true
alert('3. '+(document.getElementById('the_iframe') == window.frames['the_iframe'])); //false
alert('num of input == '+ document.getElementById("the_iframe").contentWindow.document.getElementsByTagName('input').length);
alert('div.innerHTML == '+ document.getElementById("the_iframe").contentWindow.document.getElementById('the_div').innerHTML);
alert('second input == '+ document.getElementById("the_iframe").contentWindow.document.getElementsByTagName('input')[1].value);
//求助, 以上各句在IE上都能正确执行, 但是到了火狐和Netscape上 头两句 和最后三句 都不能正确执行!!!, 求助!!!!
// 求各位高手帮小弟写出规范的能再Netscape和火狐上都能取得 iframe文档中的 input的各个值 和 id为the_div的div标签里的innerHTML的javascript语句
</SCRIPT>
</body>
</html>
没想到应该先open, 再write, 最后close, 是吗????
而我一直都是直接write的!!!
再次谢谢了!!!