0

Im trying around with HTML and found the -tag. I provided an url as src and the website does load without problems. However I canot get the HTML-Code of this inner website. How can I access it with JS?

I already tried

innerHTML, children, childNodes
etc.

HTML

<div class="Webframe">
            <embed id="webframe" src="http://testapp.galenframework.com/"></embed> 
</div>

Console output of

let webframe = document.getElementById("webframe");
console.log(webframe)

can be seen here

https://i.stack.imgur.com/lFFUP.jpg

If anyone has an idea how to access this #document, I would be happy to try it out

Thank you in advance

Taldorr
  • 175
  • 1
  • 4
  • 11

2 Answers2

0

Your first problem is the lack of interface to do your task with <embed>. Better to use <iframe>.

The second is to try to access content from another domain without CORS. (See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin)

Lets try a local page in a <iframe>. Now you can access the iframescontentDocument`:

<iframe id="webframe" src="test2.html"></iframe> 

<script>
let webframe = document.getElementById("webframe");
webframe.onload = ()=> console.log(webframe.contentDocument.body.outerHTML);
</script>

If you have access to another domain server, you can add "Access-Control-Allow-Origin: *" to the HTTP header and try it.

Aurium
  • 599
  • 5
  • 12
-1
    <div class="Webframe">
     <embed id="webframe" src="http://testapp.galenframework.com/" /> 
   </div>
   let webframe = document.getElementById("webframe");
   console.log(webframe)
tifla
  • 39
  • 1
  • 4
  • Keep in mind that most modern browsers have deprecated and removed support for browser plug-ins, so relying upon is generally not wise if you want your site to be operable on the average user's browser. – tifla Apr 11 '19 at 16:40
  • i use it in electron, can this get a probelm in the fututre? – Taldorr Apr 11 '19 at 17:07