1 <!DOCTYPE html>
2 <html lang="en">
3 <head>
4 <meta charset="UTF-8">
5 <title>Title</title>
6 </head>
7 <body>
8 <iframe id="myFrame" src="//player.bilibili.com/player.html?bvid=BV1Sv41177W7&danmaku=true&autoplay=false&poster=false" scrolling="no" border="0" frameborder="no"
9 width="800"
10 height="600"
11 framespacing="0" allowfullscreen="true"></iframe>
12
13 <button onClick="aaa()">test1</button>
14 <script>
15
16 function aaa() {
17 let iframe = document.getElementById('myFrame')
18 console.log(iframe.contentDocument)
19
20 // 跨域是不能取到 iframe的 contentDocument
21 let iframe_head =
22 iframe?.contentDocument.getElementsByClassName('bpx-player-relation-button')?.[0]
23
24 iframe_head.style.display = 'none'
25 console.log(iframe_head)
26 }
27 </script>
28 </body>
29 </html>