以下代码可以在IE6+上运行
thisMessagePreFormat = document.getElementById('child').contentWindow
.window.document.getElementById('childcont').innerHTML;我在谷歌上搜索过并尝试过各种方法...
alert(window.frames['child'].document.getElementById('childcont').innerHTML);
alert(document.frames('child').window.document
.getElementById('childcont').innerHTML);
alert(document.frames('child').document.getElementById('childcont').innerHTML);
alert(document.getElementById('child').contentWindow.window
.document.getElementById('childcont').body.innerHTML);但是,我不能从子脚本访问该值。我知道这通常会有安全风险,但在这种情况下,这不是问题。
编辑:
<html><head></head>
<script language="JavaScript">
function receive() {
alert(document.getElementById('child').contentWindow.document.getElementById('childcont').innerHTML);
alert('Send Message');
alert('EE ' + document.getElementById('child').contentWindow.document.getElementById('childcont').innerHTML);
alert('US ' + document.getElementById('child').contentWindow.window.document.getElementById('childcont').innerHTML);
alert('ME ' + document.getElementById('child').contentWindow.document.getElementById('childcont').valueOf);
alert('EE ' + document.getElementById('child').contentWindow.document.getElementById('childcont').innerHTML);
//alert('US ' + document.getElementById('child').contentWindow.window.document.getElementById('childcont').innerHTML);
}
</script>
<iframe id="child" name="child" src="window/bottom.html" ></iframe>
<table style="CURSOR: pointer; display: inline;" cellpadding="0" cellspacing="0" onClick="javascript:receive();">
<tr><td height="17"><nobr> Send </nobr></td>
</tr>
</table>
</html>在window/bottom.html上我有...
<html><head></head>
<body topmargin="0" rightmargin="0" bottommargin="0" leftmargin="0">
<table cellpadding="0" cellspacing="0" style="border:1px solid gray;">
<tr><td>
<textarea id="childcont"></textarea>
</td></tr></table>
</body>
</html>我已经尝试将值输入到父脚本中的子对象文本框中。
发布于 2011-09-13 22:13:05
你看错方向了。
将.innerHTML更改为.value
alert(window.frames['child'].document.getElementById('childcont').value);发布于 2011-09-13 00:05:54
我试着用
document.getElementById('child').contentWindow.document.getElementById('childcont').innerHTML;在FF中,它运行良好。虽然它不是跨域的,但它应该可以工作
您在第四次警告尝试时的错误是: contentWindow是iframe的窗口,它没有窗口属性。此外,#childcont不会有主体,因为它是一个元素,而不是文档
https://stackoverflow.com/questions/7390602
复制相似问题