fullscreen.js.下载 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. var FullScreenManager = (function(){
  2. function on(){
  3. console.log("----全屏----");
  4. var el = document.documentElement;
  5. var rfs = el.requestFullScreen || el.webkitRequestFullScreen ||
  6. el.mozRequestFullScreen || el.msRequestFullScreen;
  7. if (rfs) { //typeof rfs != "undefined" && rfs
  8. rfs.call(el);
  9. } else if (typeof window.ActiveXObject != "undefined") {
  10. //for IE,这里其实就是模拟了按下键盘的F11,使浏览器全屏
  11. var wscript = new ActiveXObject("WScript.Shell");
  12. if (wscript != null) {
  13. wscript.SendKeys("{F11}");
  14. }
  15. }
  16. }
  17. function off(){
  18. var el = document;
  19. var cfs = el.cancelFullScreen || el.webkitCancelFullScreen ||
  20. el.mozCancelFullScreen || el.exitFullScreen;
  21. if (cfs) { //typeof cfs != "undefined" && cfs
  22. cfs.call(el);
  23. } else if (typeof window.ActiveXObject != "undefined") {
  24. //for IE,这里和fullScreen相同,模拟按下F11键退出全屏
  25. var wscript = new ActiveXObject("WScript.Shell");
  26. if (wscript != null) {
  27. wscript.SendKeys("{F11}");
  28. }
  29. }
  30. }
  31. function click(){
  32. $(window).unbind();
  33. //全屏事件需要手动触发,由于浏览器的安全
  34. $("body").one('click',function(){
  35. on();
  36. });
  37. $("body").trigger("click");
  38. }
  39. return {on: on, off: off,click:click};
  40. })();