Javascript Element.requestFullscreen () - undefined

How to use the code if 'element.requestFullscreen ()' is undefined?

 if(element.webkitRequestFullScreen) { 
    element.webkitRequestFullScreen();
  }

      

+3


source to share


1 answer


If it requestFullscreen

returns undefined

, it means that you cannot ask for full screen mode, because this function does not exist. Every browser other than IE10 and below supports it, but you need to use the right vendor prefix as you commented. A good way to do this is to do

var requestFullScreen = elem.requestFullscreen || elem.msRequestFullscreen || elem.mozRequestFullScreen || elem.webkitRequestFullscreen;

      

I think your problem is that you have defined some functions incorrectly. this is confusing because Mozilla uses .mozRequestFull S , while others use requestFull s . Capital S can be annoying.



where elem

is an element video

from the DOM. Then you can do requestFullScreen.call(elem)

and it will start full screen.

And as @ArunPJohny commented, definitely take a look at the MDN article .

+8


source







All Articles