0

I want to get all images from a iframe and turn it into a array to get it src

var iframe = document.getElementById('iframeId');
var innerDoc = iframe.contentDocument || iframe.contentWindow.document;

var images = innerDoc.getElementsByTagName("img").innerHTML;
document.getElementById("inv").innerHTML = document.getElementById("inv").innerHTML + "<br>"+ images[0].src;

error: Uncaught DOMException: Blocked a frame with origin "null" from accessing a cross-origin frame. at update (file:///H:/images.html:56:63)

error: Uncaught DOMException: Blocked a frame with origin "http://localhost" from accessing a cross-origin frame. at update (http://localhost/images.html:56:63)

  • 1
    Does this answer your question? [SecurityError: Blocked a frame with origin from accessing a cross-origin frame](https://stackoverflow.com/questions/25098021/securityerror-blocked-a-frame-with-origin-from-accessing-a-cross-origin-frame). Also see [JavaScript document.domain Uncaught DOMException: Blocked a frame with origin](https://stackoverflow.com/questions/54879607/javascript-document-domain-uncaught-domexception-blocked-a-frame-with-origin). – showdev Mar 27 '23 at 06:00
  • also tried with xamp – jhu unhn hefhd Mar 27 '23 at 06:08
  • As an aside, please review what the `getElementsByTagName` method returns, and check if image elements can have `innerHTML` content. (hint: they don't take closing tags). – traktor Mar 27 '23 at 06:08

0 Answers0