[HTML] enterFullScreen vs webkitEnterFullScreen

2,854 views
Skip to first unread message

Jean-Baptiste Richardet

unread,
Jun 16, 2014, 5:37:55 AM6/16/14
to haxe...@googlegroups.com
Hi,

I got an error when trying to use VideoElement.enterFullScreen() on Chrome and discovered that it use a similar function named webkitEnterFullScreen().

I noticed there are two entries in Haxe manual for enterFullScreen(), is that the answer to my problem? If it is, how can I switch between those too? And if it's not, is there a more elegant solution than to check the userAgent and use __js__ magic if it's webkit?

Thanks,

Jean-Baptiste Richardet

Andreas Mokros

unread,
Jun 16, 2014, 6:17:23 AM6/16/14
to haxe...@googlegroups.com
Hi.

On Mon, 16 Jun 2014 02:37:55 -0700 (PDT)
Jean-Baptiste Richardet <jeanbaptist...@gmail.com> wrote:
> I noticed there are two entries in Haxe manual
> <http://api.haxe.org//////js/html/VideoElement.html> for
> enterFullScreen(), is that the answer to my problem? If it is, how
> can I switch between those too? And if it's not, is there a more
> elegant solution than to check the userAgent and use __js__ magic if
> it's webkit?

It highly depends on what you actually want to do. The real
Fullscreen-API (requestFullscreen) is much more complicated with several
different prefixes and method names for the different browsers. I once
wrote a wrapper for this. Basically you check if the method exists,
like:
untyped document["webkitEnterFullscreen"] != undefined
But I only use webkitEnterFullscreen on iOS, if I remember correctly.

--
Mockey

Sam MacPherson

unread,
Jun 16, 2014, 6:08:02 PM6/16/14
to haxe...@googlegroups.com
Here is what I use:

function requestFullScreen ():Void {
untyped __js__("if (document.documentElement.requestFullscreen) document.documentElement.requestFullscreen(); else if (document.documentElement.mozRequestFullScreen) document.documentElement.mozRequestFullScreen(); else if (document.documentElement.webkitRequestFullscreen) document.documentElement.webkitRequestFullscreen(); else if (document.documentElement.msRequestFullscreen) document.documentElement.msRequestFullscreen();");
}
function cancelFullScreen ():Void {
untyped __js__("if (document.exitFullscreen) document.exitFullscreen(); else if (document.mozCancelFullScreen) document.mozCancelFullScreen(); else if (document.webkitExitFullscreen) document.webkitExitFullscreen(); else if (document.msExitFullscreen) document.msExitFullscreen();");
}

Swap out the document for the element if you want to full screen a video element.

Andreas Mokros

unread,
Jun 17, 2014, 5:36:58 AM6/17/14
to haxe...@googlegroups.com
Hi.

On Mon, 16 Jun 2014 15:08:02 -0700 (PDT)
Sam MacPherson <xyl...@gmail.com> wrote:
> function requestFullScreen ():Void {
> untyped __js__("if (document.documentElement.requestFullscreen)
> document.documentElement.requestFullscreen(); else if
> (document.documentElement.mozRequestFullScreen)
> document.documentElement.mozRequestFullScreen(); else if
> (document.documentElement.webkitRequestFullscreen)
> document.documentElement.webkitRequestFullscreen(); else if
> (document.documentElement.msRequestFullscreen)
> document.documentElement.msRequestFullscreen();");
> }

Should work, but not a very good approach IMO. I think it's better to
check the API once and not on every function call.
BTW: You're missing older webkit (Chrome < 20, Safari < 6) with this
where it's webkitRequestFullScreen (not so important anymore, probably).

Also the question was actually about enterFullScreen, which is something
else.

--
Mockey

Juraj Kirchheim

unread,
Jun 17, 2014, 8:04:07 AM6/17/14
to haxe...@googlegroups.com
I would think the best idea is to have a polyfill that patches the
respective prototype and then just write code against the standard DOM
api.
> --
> To post to this group haxe...@googlegroups.com
> http://groups.google.com/group/haxelang?hl=en
> ---
> You received this message because you are subscribed to the Google Groups "Haxe" group.
> For more options, visit https://groups.google.com/d/optout.

der Raab

unread,
Mar 11, 2015, 6:53:06 AM3/11/15
to haxe...@googlegroups.com
This topic is a little older but I struggled with the same issue and found this polyfill:

It works just fine except one issue:
Checking for Browser.document.fullscreenEnabled doesn't work on IE 11, so simply check if fullscreenElement is null:

var fullscreenEnabled = ( Browser.document.fullscreenElement != null );

Just in case you run into the same problem.
Reply all
Reply to author
Forward
0 new messages