javascript - webkitRequestFullScreen is not a function - Stack Overflow

I was trying to call a function to make the screen return to full screen mode when ESC is pressed. (Tha

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745143524a4613540.html

相关推荐

  • javascript - webkitRequestFullScreen is not a function - Stack Overflow

    I was trying to call a function to make the screen return to full screen mode when ESC is pressed. (Tha

    2小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信