Reputation: 134
My html code is below
I need to access input elements in b.html. Please provide me javascript suggestions. i am getting error while trying through chrome console
FIRST ATTEMPT:
document.getElementsByName['body'].contentDocument
VM331:2 Uncaught TypeError: Cannot read property 'contentDocument' of undefined
document.getElementsByName['body'].contentWindow.document
VM347:2 Uncaught TypeError: Cannot read property 'contentWindow' of undefined
2nd ATTEMPT:
var theFrame = document.getElementsByTagName("frame")[2];
var theFrameDocument = theFrame.contentWindow.document;
var button = theFrameDocument.getElementsByTagName("input");
VM494:3 Uncaught DOMException: Blocked a frame with origin "null" from accessing a cross-origin frame.
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>
Upvotes: 1
Views: 395
Reputation: 943634
Security restrictions prevent access to other files from documents served via file://
.
Run a web server and load the documents over HTTP instead.
Upvotes: 1