1

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>
    &amp;lt;BODY&amp;gt;
    &amp;lt;/BODY&amp;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>
naveen
  • 104
  • 7
  • For obvious security reasons you cannot - http://stackoverflow.com/questions/25098021/securityerror-blocked-a-frame-with-origin-from-accessing-a-cross-origin-frame – ElliotM Mar 23 '15 at 19:11

1 Answers1

1

Security restrictions prevent access to other files from documents served via file://.

Run a web server and load the documents over HTTP instead.

Quentin
  • 800,325
  • 104
  • 1,079
  • 1,205