在文档中,Constructors
它声明:“在本例中,页面上的<iframe>
元素已经定义了将使用API的播放器。请注意,无论是播放机的src必须将enablejsapi参数设置为1,还是必须将<iframe>
元素的enablej皂i属性设置为true。”
我似乎不能让这件事起作用。当我将?enablejsapi=1附加到url时,我的简单测试页面工作得很好,但是当将这个参数作为属性添加到iframe时,它不起作用。
如何使用属性启用api?
谢谢-edit:有什么想法吗?
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>YouTube Player API Test </title>
</head>
<body>
<iframe id="existing-iframe-example" width="640" height="360" src="https://www.youtube-nocookie.com/embed/M7lc1UVf-VE" enablejsapi="1" frameborder="0" allowfullscreen></iframe>
<!--
<iframe id="existing-iframe-example" width="640" height="360" src="https://www.youtube-nocookie.com/embed/M7lc1UVf-VE?enablejsapi=1" frameborder="0" allowfullscreen></iframe>
-->
<script src="https://www.youtube.com/iframe_api"></script>
<script type="text/javascript">
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('existing-iframe-example');
}
</script>
<button id="playVideo" onClick="player.playVideo()">playVideo</button><br />
</body>
</html>
发布于 2021-01-02 04:21:00
attribute
是指true
或false
。在url
中,1
或0
是enablejsapi。
因此,只要您使用enablejsapi作为HTML attribute
,,就必须使用true
或false
,,而不是像url中那样使用1
或0
。
https://stackoverflow.com/questions/51109436
复制相似问题