我有一个看起来像这样的iframe
<iframe name="myframe1" id="myframe1" width="100%" height="100%" src="a.html">
<html>
<head></head>
<frameset name="myframe2" cols="0%, 100%" border="0" frameBorder="0" frameSpacing="0">
<frame name="page1" src="c.html" scrolling="no"></frame>
<frame name="page2" src="d.html" >
<html>
<head></head>
<body class="top">
<div class="div1">
<div class="div2">
<div class="div3">
<ul class="x">
<li>a</li>
<li>b</li>
</ul>
</div>
</div>
</div>
</body>
</html>
</frame>
</frameset>
</html>
</iframe>
我想引用元素x
。我尝试了几种方法,但我找不到解决方案。
document.getElementsByTagName('iframe')[0].contentWindow.document.getElementsByClassName('ads')[0]
我收到以下错误:
VM257:1 Uncaught DOMException: Blocked a frame with origin "http://www. exampleMY SITE.com" from accessing a cross-origin frame.
at <anonymous>:1:57
(anonymous) @ VM257:1
document.getElementsByTagName('iframe')[0].contentDocument.document.getElementsByClassName('ads')[0]
VM626:1 Uncaught DOMException: Failed to read the 'contentDocument' property from 'HTMLIFrameElement': Blocked a frame with origin "http:// exampleMYIFRAME.COM" from accessing a cross-origin frame.
at <anonymous>:1:43