I have a document that is embedded in my site by using an iFrame. The iFrame is from Box.com document viewer. The iFrame has its own built in fullscreen button. The fullscreen button is within the iFrame so I cannot attach a click event listener to the button. I added the attribute allowfullscreen to the iFrame to allow it to go fullscreen.
I want to do something like this:
$('iframe').on 'EnterFullScreen', () ->
# Run function
But what event do I have to listen to, to detect when the iFrame is going fullscreen?
Here is a jsfiddle with the type of document I am embedding. The goal is to detect when the document goes fullscreen.
http://jsfiddle.net/Rnvcm
The ” iframe ” tag defines a rectangular region within the document in which the browser can display a separate document, including scrollbars and borders. An inline frame is used to embed another document within the current HTML document. For the fullscreen Iframe, you have to cover the entire viewport.
The fullscreenElement property tells you the Element that's currently being displayed in fullscreen mode on the DOM (or shadow DOM). If this is null , the document (or shadow DOM) is not in fullscreen mode. The fullscreenEnabled property tells you whether or not it is possible to engage fullscreen mode.
You can listen for a fullscreen change in your parent page (the one having the iframe
):
function changeHandler(e) {
// Mode has changed.
}
document.addEventListener("fullscreenchange", changeHandler, false);
document.addEventListener("webkitfullscreenchange", changeHandler, false);
document.addEventListener("mozfullscreenchange", changeHandler, false);
Using the events pointed out by putvande you can still bind your own enterFullScreen
event:
$(document).on('fullscreenchange mozfullscreenchange webkitfullscreenchange msfullscreenchange', function() {
if (document.fullScreen || document.mozFullScreen || document.webkitIsFullScreen || document.msFullscreenElement)
{
$(document).trigger('enterFullScreen');
}
else
{
$(document).trigger('leaveFullScreen');
}
});
You can use the simpler enterFullScreen
event now using:
$(document).on('enterFullScreen', function(){
// Do stuff
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With