首页 > 代码库 > javascript 实现全屏

javascript 实现全屏

1 可以添加事件,全屏错误事件

2 IE11以上

3 chrome全屏需要设置元素的宽度、高度,否则显示的是缩略大小

GLOBAL.BigScreen = function(node){   this._enable = false;  this._node = null;  var v_node = typeof node == "string" ? document.getElementById(node) : node;  if(typeof(v_node) == "undefined" || v_node == null)  {     this._node = document;  }else  {     this._node = v_node;  }  if (document.fullscreenEnabled ||document.webkitFullscreenEnabled ||document.mozFullScreenEnabled ||document.msFullscreenEnabled)  {      this._enable = true;  }}GLOBAL.BigScreen.prototype.enable = function(){   return this._enable;}GLOBAL.BigScreen.prototype.isFullScreen = function(){   if(document.fullscreenElement ||document.webkitFullscreenElement ||document.mozFullScreenElement ||document.msFullscreenElement)   {      return true;   }else   {      return false;   }}GLOBAL.BigScreen.prototype.toggle = function(){     if(this._enable == false)   {      this._defaultToFullScreen();      return;   }   var req = null;   if(this.isFullScreen())   {      req = this._node.exitFullscreen|| this._node.webkitExitFullscreen || this._node.mozCancelFullScreen || this._node.msExitFullscreen;      req.call(this._node);    }else  {    if(this._node.nodeName == "#document")   {       req = this._node.body.requestFullscreen || this._node.body.webkitRequestFullscreen || this._node.body.mozRequestFullScreen || this._node.body.msRequestFullscreen;       req.call(this._node.body);   }   else   {       req = this._node.requestFullscreen || this._node.webkitRequestFullscreen || this._node.mozRequestFullScreen || this._node.msRequestFullscreen;       req.call(this._node);   }  } }GLOBAL.BigScreen.prototype.addOnFullScreenError = function(handler,scope){      if(this._enable == false)          return  null;      if (document.fullscreenEnabled) {          return GLOBAL.Event.on(document,"fullscreenerror",handler,scope);      } else if (document.webkitFullscreenEnabled) {          return  GLOBAL.Event.on(document,"webkitfullscreenerror",handler,scope);      } else if (document.mozFullScreenEnabled) {          return GLOBAL.Event.on(document,"mozfullscreenerror",handler,scope);      } else if (document.msFullscreenEnabled) {          return GLOBAL.Event.on(document,"MSFullscreenError",handler,scope);      }  } GLOBAL.BigScreen.prototype.addOnFullscreenChange= function(handler,scope){      if(this._enable == false)          return;      if (document.fullscreenEnabled) {           GLOBAL.Event.on(document,"fullscreenchange",handler,scope);       } else if (document.webkitFullscreenEnabled) {           GLOBAL.Event.on(document,"webkitfullscreenchange",handler,scope);       } else if (document.mozFullScreenEnabled) {           GLOBAL.Event.on(document,"mozfullscreenchange",handler,scope);       } else if (document.msFullscreenEnabled) {            GLOBAL.Event.on(document,"MSFullscreenChange",handler,scope);        }  } GLOBAL.BigScreen.prototype._defaultToFullScreen = function(){       if(this._enable)      return;    if (typeof window.ActiveXObject !== "undefined") {    var wscript = new ActiveXObject("WScript.Shell");    if (wscript !== null) {      wscript.SendKeys("{F11}");    }  }}

 

javascript 实现全屏