简体   繁体   中英

Detecting Event change in fullscreen mode Internet explorer

I am trying to write an event handler that detects whether a video player I have is in fullscreen or 'regular' mode.

I have tried using

 document.addEventListener("fullscreenchange", myfunc, false);

but this doesn't work in IE, I have implemnted the same thing for firefox and chrome using webkitfullscreenchange and mozfullscreenchange event. Is there any other event I can use in IE for this? Or another way of doing this?

Any help would be appreciated. Thanks!

You have jQuery, so use it:

var screen_change_events = "webkitfullscreenchange mozfullscreenchange fullscreenchange MSFullscreenChange";
$(document).on(screen_change_events, function () {

});

( addEventListener isn't supported in versions earlier than IE 9 anyways)

At the same time, it doesn't look like full screen is supported in any version of IE:

MDN Reference:

Here's a possible hack around it:

There is a jQuery plugin named jquery-fullscreen that will do exactly what you want. Until the Fullscreen-API standard has crystallized this is probably the best option.

You can also use the Modernizr fullscreen-api check and shim it if the browser doesn't support it by firing the event yourself (see this question for a detection method)

download this script: https://raw.githubusercontent.com/sindresorhus/screenfull.js/gh-pages/dist/screenfull.js

use this code:

if (screenfull.enabled) {
    screenfull.onchange(() => {
        icono_full(screenfull.isFullscreen);
    });
}


function icono_full(x) {
    if (x == true) {
        //do when full screen is on
    } else {
        //not full screen
    }
}

see: https://github.com/sindresorhus/screenfull.js

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM