Alvaro Silvino
Alvaro Silvino

Reputation: 9743

jQuery 1.5.2 get fullscreen event Chrome

I need to capture the event of fullscreen (fullscreen on and fullscreen exit)

Using the latest I was successfully able to achieve this with:

 $(document).on('mozfullscreenchange webkitfullscreenchange fullscreenchange',function(){
         alert("fullscreen capture");
     });

Using jQuery 1.5.2

Any ideas?

I understand to use .live() and .delegate(), but I wasn't able to capture this event.

Upvotes: 0

Views: 42

Answers (2)

Niki van Stein
Niki van Stein

Reputation: 10724

From the firefox docs:

When fullscreen mode is successfully engaged, the document which contains the element receives a mozfullscreenchange event. When fullscreen mode is exited, the document again receives a mozfullscreenchange event. Note that the mozfullscreenchange event doesn't provide any information itself as to whether the document is entering or exiting fullscreen mode, but if the document has a non null mozFullScreenElement, you know you're in fullscreen mode.

To get this information for all major browsers use

var fullscreenElement = document.fullscreenElement || document.mozFullScreenElement || document.webkitFullscreenElement;
var fullscreenEnabled = document.fullscreenEnabled || document.mozFullScreenEnabled || document.webkitFullscreenEnabled;

Also check this site for a lot of usefull tips and code regarding the fullscreen event.

Upvotes: 1

gen_Eric
gen_Eric

Reputation: 227240

Use .bind() to do this in an old version of jQuery.

$(document).bind('mozfullscreenchange webkitfullscreenchange fullscreenchange', function(){
    alert("fullscreen capture");
});

P.S. .live()/.delegate() are for "delegated" events. That is, binding events to elements that may not exist at that time. In newer jQuery versions, you would do:

$('#parentElement').on('click', '.child', function(){})

Upvotes: 3

Related Questions