最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - webkitRequestFullScreen is not a function - Stack Overflow

programmeradmin1浏览0评论

I was trying to call a function to make the screen return to full screen mode when ESC is pressed. (That is, when ESC is pressed the screen goes to normal mode. I need to make it go back to full screen mode.) I identified that the ESC click event called the full screen function again like,

$(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 I’m getting this error:

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

I was trying to call a function to make the screen return to full screen mode when ESC is pressed. (That is, when ESC is pressed the screen goes to normal mode. I need to make it go back to full screen mode.) I identified that the ESC click event called the full screen function again like,

$(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 I’m getting this error:

Uncaught TypeError: $(...).webkitRequestFullScreen is not a function
Share Improve this question edited Sep 10, 2024 at 12:04 TRiG 10.7k9 gold badges61 silver badges111 bronze badges asked Apr 26, 2017 at 5:09 NidheeshNidheesh 4,56230 gold badges93 silver badges156 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

With $("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.

You can get the elements from a jQuery object by indexing them like you would with an array (i.e. $("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:

In your HTML:

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

In your 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. To see the different methods available on different browsers and how to call them, see the MDN docs.

发布评论

评论列表(0)

  1. 暂无评论