简体   繁体   English

webkitRequestFullScreen不是函数

[英]webkitRequestFullScreen is not a function

I was trying to call a function to make the screen in full screen mode again , when ESC is pressed.(that is when ESC is pressed the screen goes normal mode.I need to make it again in full screen).Identified the ESC click event called the full screen function again like, 我试图调用一个函数以在按下ESC时再次将其显示为全屏模式(也就是说,当按下ESC时,屏幕进入正常模式。我需要再次将其设置为全屏显示)。再次称为全屏功能的事件,

$(document).ready(function (){
var screen_change_events = "webkitfullscreenchange mozfullscreenchange fullscreenchange MSFullscreenChange";
$(document).on(screen_change_events, function () {
if (!window.screenTop && !window.screenY) {
$("iframe")['webkitRequestFullScreen'](); // Identified that ESC is triggered.So need to make it again fullscreen mode
}else{
//alert("no")
}
});
});

But getting the below error. 但是出现以下错误。

Uncaught TypeError: $(...).webkitRequestFullScreen is not a function

With $("iframe")['webkitRequestFullScreen'](); 使用$("iframe")['webkitRequestFullScreen'](); you are making a jQuery object and attempting to call its "webkitRequestFullScreen" method, but jQuery objects don't have this method - only element objects do. 您正在制作jQuery对象并尝试调用其“ webkitRequestFullScreen”方法,但jQuery对象没有此方法-仅元素对象有。

You can get the elements from a jQuery object by indexing them like you would with an array (ie $("iframe")[0].webkitRequestFullScreen() ), but if you can, it's best to give the iframe element that you are selecting a unique ID, and then use that: 您可以通过像对数组那样对它们进行索引(例如$("iframe")[0].webkitRequestFullScreen() )来从jQuery对象中获取元素,但是,如果可以的话,最好给出一个iframe元素选择一个唯一的ID,然后使用该ID:

In your HTML: 在您的HTML中:

<iframe id="myvideo" src="..."></iframe>

In your JavaScript: 在您的JavaScript中:

var elem = document.getElementById("myvideo");
if (elem.webkitRequestFullscreen) {
  elem.webkitRequestFullscreen();
}

Also, note that prefixing the method with "webkit" will only work on Webkit-based browsers. 另外,请注意,以“ webkit”为前缀的方法仅适用于基于Webkit的浏览器。 To see the different methods available on different browsers and how to call them, see the MDN docs . 要查看不同浏览器上可用的不同方法以及如何调用它们,请参阅MDN文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM