未捕获的TypeError:对象#<htmlelement>没有方法'webkitEnterFullScreen'</htmlelement>

时间:2012-06-02 01:07:16

标签: jquery html5 fullscreen

我正在尝试在弹出窗口中使用html5全屏api,但我一直收到此错误:

Uncaught TypeError: Object #<HTMLElement> has no method 'webkitEnterFullScreen' 

这是我的HTML:

<html lang="en"><head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>Negar - one</title>
        <script type="text/javascript" src="/Negar/js/jquery-1.7.2.min.js"></script>
        <script type="text/javascript" src="/Negar/js/viewer.js"></script>
        <style type="text/css">
        #main-content{height: 100%; width: 100%; position: absolute;
            -webkit-transition: -webkit-transform 1s ease-in;
               -moz-transition: -moz-transform 1s ease-in;
                -ms-transition: -ms-transform 1s ease-in;
                    transition: transform 1s ease-in;
            }
        </style>
    </head><link rel="stylesheet" type="text/css" href="data:text/css,">

    <body>
        <section id="main-content">   some code here   </section>

</body></html>

这是我的功能:

$("#main-content").get(0).webkitEnterFullScreen();

3 个答案:

答案 0 :(得分:2)

进入全屏的请求应该来自用户。你可以尝试这样的东西来实现你想要做的事情:

<script>
    function goFs(id) {
        var element = document.getElementById(id);

        if (element.mozRequestFullScreen) {
            element.mozRequestFullScreen();
        } else if (element.webkitRequestFullScreen) {
            element.webkitRequestFullScreen();
        }
    }
</script>

<div id="test">
    Hi there!
</div>

<button onclick="goFs('test');">Full screen?</button>

示例:http://fiddle.jshell.net/73Wus/show/

注意:我必须分享完整的jsFiddle页面,因为iframe需要一个特殊的属性来允许全屏,如下所示:

<iframe src="127.0.0.1" allowFullScreen></iframe>

...可以找到常用小提琴here

答案 1 :(得分:1)

我担心webkitEnterFullScreen()仅适用于视频元素。

请参阅API manual

尝试

<video id="my-video"></video>

$("#my-video")[0].webkitEnterFullScreen();

答案 2 :(得分:0)

试试这个:

$("#main-content")[0].webkitEnterFullScreen();