我的html代码位于
之下我需要访问b.html中的输入元素。请提供我的javascript建议。我在尝试通过Chrome控制台时遇到错误
第一次尝试:
document.getElementsByName['body'].contentDocument
VM331:2未捕获的TypeError:无法读取未定义的属性'contentDocument'
document.getElementsByName['body'].contentWindow.document
VM347:2未捕获的TypeError:无法读取未定义的属性'contentWindow'
第二次尝试:
var theFrame = document.getElementsByTagName("frame")[2];
var theFrameDocument = theFrame.contentWindow.document;
var button = theFrameDocument.getElementsByTagName("input");
VM494:3未捕获DOMException:阻止原始“null”的帧访问跨源帧。
main.html中
<html>
<frameset framepadding="0" framespacing="0" bgcolor="#F0E68C" border="0" frameborder="no">
<frameset rows="16%,*">
<frame bgcolor="white" src="h.html" name="header" marginwidth="15" marginheight="40" scrolling="no" frameborder="0" noresize="" width="100%">
<frameset bordercolor="#F0E68C" cols="200px,*">
<frame src="l.html" name="left"/>
<frame src="b.html" id="body1" name="body"/>
</frameset>
</frameset>
<noframes>
&lt;BODY&gt;
&lt;/BODY&gt;
</noframes>
</frameset>
</html>
h.html
<html>
<body>
header
</body>
</html>
l.html
<html>
<body>
left
</body>
</html>
b.html
<html>
<body>
body
<input id="input1" value="empty" type="text" name="txtProdCoating" size="25">
</body>
</html>
答案 0 :(得分:1)
安全限制阻止访问通过file://
提供的文档中的其他文件。
运行Web服务器并通过HTTP加载文档。