DOM异常11带有webkitEnterFullscreen()的InvalidStateError

时间:2013-06-12 18:50:11

标签: javascript html5 webkit html5-video fullscreen

我正在使用Chrome,我的HTML是

<!DOCTYPE html>
<html>
<head>
    <script type="text/javascript">
        window.onload = function() {
            var vid = document.createElement('video');
            vid.src = "small.mp4";
            document.body.appendChild(vid);
            vid.addEventListener("loadedmetadata", function() {
                vid.webkitEnterFullscreen();
            });
        };
    </script>
</head>
<body>
</body>
</html>

我在vid.webkitEnterFullscreen();

上收到错误

1 个答案:

答案 0 :(得分:1)

您无权在'loadedmetadata'事件中输入全屏。你必须等待点击/按键事件。

window.onload = function() {
        var vid = document.createElement('video');
        vid.src = "small.mp4";
        document.body.appendChild(vid);
        vid.play();
        vid.addEventListener("click", function() {
            vid.webkitEnterFullscreen();
        });
 };