问题
As per https://developers.google.com/youtube/iframe_api_reference
player.getIframe():Object
This method returns the DOM node for the embedded <iframe>.
How can I access the elements of the DOM node like I can do with the parent page's DOM, such as document.getElementById("example")
?
回答1:
Here are the children under that player.getIframe():Object
<iframe id="player" frameborder="0" allowfullscreen="1" title="YouTube video player" width="640" height="390" src="https://www.youtube.com/embed/R98hoTffg0E?enablejsapi=1&origin=http%3A%2F%2Flocalhost%3A8080&widgetid=1"></iframe>
in short, they are:
id, frameborder, allowfullscreen, title, width, height, src
To access them, you'd do something like:
player.getIframe().id
player.getIframe().title
player
is the youtube player instance taken from the same docs you provided.
来源:https://stackoverflow.com/questions/46124910/accessing-elements-from-player-getiframe-object