utilities.js
var FullScreen = { toggle : function(element) { element = element || document.body; var full = (document.fullScreenElement && document.fullScreenElement !== null) || (document.mozFullScreen || document.webkitIsFullScreen); var requestScreen; if (full) { element = document; requestScreen = element.cancelFullScreen || element.webkitCancelFullScreen || element.mozCancelFullScreen || element.exitFullscreen; } else { requestScreen = element.requestFullScreen || element.webkitRequestFullScreen || element.mozRequestFullScreen || element.msRequestFullScreen; } if (requestScreen) { // Native full screen. requestScreen.call(element); } else if (typeof window.ActiveXObject !== "undefined") { // Older IE. var wscript = new ActiveXObject("WScript.Shell"); if (wscript !== null) { wscript.SendKeys("{F11}"); } } } }Example to use
<html> <head> <style type="text/css"> body{ width : 100%; height : 100%; padding : 0px; margin : 0px; } </style> <script type="text/javascript" src="utilities.js"></script> </head> <body> <button onclick="FullScreen.toggle(document.body);">Toggle Full Screen</button> </body> </html>
ไม่มีความคิดเห็น:
แสดงความคิดเห็น