HTML5 FullScreen API toggle with JavaScript -
i trying make button toggle (on/off) html5 fullscreen on website.
after reading plenty of documentation, appears there still inconsistencies among how browsers treat properties it.
i went kind of "cross-browser" approach does work in firefox , safari/macos, partially works in safari/windows , totally fails work in chrome , opera.
some castrated code snippets:
// class init initialize: function() { this.elmbuttonfullscreen = $('fullscreen'); this.elmbuttonfullscreen.on('click', this.onclickfullscreen.bindaseventlistener(this)); }, // helper methods _launchfullscreen: function(element) { if(element.requestfullscreen) { element.requestfullscreen(); } else if(element.mozrequestfullscreen) { element.mozrequestfullscreen(); } else if(element.webkitrequestfullscreen) { element.webkitrequestfullscreen(); } }, _cancelfullscreen: function() { if(document.cancelfullscreen) { document.cancelfullscreen(); } else if(document.mozcancelfullscreen) { document.mozcancelfullscreen(); } else if(document.webkitcancelfullscreen) { document.webkitcancelfullscreen(); } }, _isfullscreen: function() { fullscreen = document.fullscreenenabled || document.mozfullscreenenabled || document.webkitfullscreenenabled ? true : false; if(this.debug) console.log('fullscreen enabled? ' + fullscreen); return fullscreen; }, // callbacks onclickfullscreen: function(e) { e.stop(); if(this._isfullscreen()) this._cancelfullscreen(); else this._launchfullscreen(document.documentelement); }
changing 1st line of _isfullscreen
function to
fullscreen = document.fullscreenenabled || document.mozfullscreenenabled || document.webkitisfullscreen ? true : false;
does trick (at least firefox, chrome , safari on mac , windows)
Comments
Post a Comment