如何让这个HTML5全屏function在Firefox中运行?
我想要一个按钮,使用HTML5全屏API触发全屏模式。 我在网上点了一些示例来获取下面的代码,但它仅适用于Safari / Chrome,因为它是特定于webkit的前缀。 我想使用moz前缀(以及标准HTML5)也可以在Firefox中使用,但我不知道如何去做。 任何建议?
HTML:
JS:
$('.fullscreen').on('click', function(){ var elem = document.getElementById('viewer'); if (document.webkitFullscreenElement) { document.webkitCancelFullScreen(); } else { elem.webkitRequestFullScreen(); }; });
你可以尝试这样的事情:
var cancelFullScreen = document.cancelFullScreen || document.webkitCancelFullScreen || document.mozCancelFullScreen || document.msCancelFullScreen; var requestFullScreen = document.requestFullScreen || document.webkitRequestFullScreen || document.mozRequestFullScreen || document.msRequestFullScreen; $('.fullscreen').on('click', function(){ var elem = document.getElementById('viewer'); var fullscreenElement = document.fullscreenElement || document.webkitFullscreenElement || document.mozFullscreenElement || document.msFullscreenElement; if (fullscreenElement) { cancelFullScreen.call(document); } else { requestFullScreen.call(document); }; });