Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Get value from another #document JavaScript !Doctype

How can I get value from another iframe?

When I inspecting the website and I click on this line:

<input type="hidden" name="1" value="q"›

And I type this to the console:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

document.getElementsByName("3")[0].value

I can get the value:

‘e’

But if I click outside from iframe, and I check the value I get this result:
VM89205:1 Uncaught TypeError: Cannot read properties of undefined (reading ‘value’)
at :1:49

Looks like I have to click inside if I want get the value. Is it possible to get the value without every time click inside?

<iframe name="frame" id="frame" src="TEST.html?token=asdasdasd" style="display: none;"> ==$0 
    #document
      <html>...</html>
     </iframe>                                                                                    
    <form name="apple" id="apple" method="get" action="test.htm?token=asdasdasd" target="dialog">  <input type="hidden" name="1" value="q"›
      <input type="hidden" name="1" value="q"›
      <input type="hidden" name="2" value="wm> 
      <input type="hidden" name="3" value="e"> 
      <input type="hidden" name="4" value="r"› 
      <input type="hidden" name="5" value="e> 
      <input type="hidden" name="6" value="z"> 
      <input type="hidden" name="7" value>
      <input type="hidden" name="8" value="u"> 
      <input type="hidden" name="9" value="i"> 
      <input type="hidden" name="10" value>

>Solution :

To access an iframe’s content from outside the iframe (provided, it’s not an external domain), use document.getElementById("frame").contentWindow.document.getElementsByName("3")[0].value;

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading