编辑:我发现问题与在没有特定 API 或类似的东西的情况下无法访问 iframe 中的元素有关。已经解决了。
我需要嵌入每日天文图片网站的图像。这是我现在拥有的html:
<head>
<style>
body, html {
margin: 0px;
padding: 0px;
}
iframe {
border: none;
}
</style>
</head>
<body>
<iframe id="iframe" width="100%" height="600px"
src="https://apod.nasa.gov/apod/astropix.html"></iframe>
<div id="PlaceToPutTable"></div>
<script src="panel.js"></script>
</body>
这是我现在拥有的 JavaScript:
var iframe = document.getElementById("iframe");
var div = document.getElementById("PlaceToPutTable");
div.innerHTML =
iframe.contentWindow.document.getElementsByTagName("a")[1];
我尝试过使用iframe.contentWindow.document.getElementByTagName("img")[0]
和不.innerHTML
遵循它。我将其用作 Opera 侧边栏扩展,因此在添加.innerHTML
:时我不断收到此错误Uncaught type error: cannot read property 'innerHTML' of undifined
。
我通过操作在此答案中获得的代码获得了此代码,但每日天文图片图像不包含id
.