JavaScript实现全屏显示

<!doctype html>
<html>
<head>
    <title>全屏显示</title>
    <meta charset="utf-8" />
    <style>

        div {
           width: 200px;
           height:200px;
           background:pink;
           margin:100px auto;
        }
        button {
            margin-left: 650px;
        }
        h1 {
            margin-left: 400px;
        }
    </style>
</head>
<body>
    <h1>js控制页面的全屏展示和退出全屏显示</h1>
    <div id="div1">onclick="window.open(document.location, ‘big‘, ‘fullscreen=yes‘)"</div>
    <button type="button" id="btn" onclick="window.open(document.location, ‘big‘, ‘fullscreen=yes‘)">全屏</button>

</body>

</html>

  方法一:

<script type="text/javascript">
       window.onload =function(){
            document.getElementById("btn").onclick = function(){
              var elem =document.getElementById("div1");
              requestFullScreen(elem);

            }
            var requestFullScreen=function(element) {
               //某个元素有请求
             var requestMethod =element.requestFullScreen
             ||element.webkitRequestFullScreen //谷歌
             ||element.mozRequestFullScreen  //火狐
             ||element.msRequestFullScreen; //IE11
            if (requestMethod) {
             requestMethod.call(element);   //执行这个请求的方法
         } else if (typeof window.ActiveXObject !== "undefined") {  //window.ActiveXObject判断是否支持ActiveX控件
              //这里其实就是模拟了按下键盘的F11,使浏览器全屏
               var wscript = new ActiveXObject("WScript.Shell"); //创建ActiveX
             if (wscript !== null) {    //创建成功
                 wscript.SendKeys("{F11}");//触发f11
             }
         }
            }
    }
</script>

  方法二:

<script>
 var btn = document.getElementById("btn"); 

btn.onclick = function() {
	var width =  window.screen.width;
	var height =   window.screen.height;
	var elem = document.getElementById("div1");
	requestFullScreen(elem);
}

function requestFullScreen(element) {
	if (element.requestFullscreen) {
		element.requestFullscreen();
	}
//FireFox
	else if (element.mozRequestFullScreen) {
		element.mozRequestFullScreen();
	}
//Chrome等
	else if (element.webkitRequestFullScreen) {
		element.webkitRequestFullScreen();
	}
//IE11
	else if (element.msRequestFullscreen) {
		element.msRequestFullscreen();
	}
};
</script>

  方法三:

    <button type="button" id="btn" onclick="window.open(document.location, ‘big‘, ‘fullscreen=yes‘)">全屏</button>

  

时间: 2024-08-25 04:07:52

JavaScript实现全屏显示的相关文章

JavaScript特效实例011-弹出全屏显示的网页模式对话框

实例011                    弹出全屏显示的网页模式对话框 实例说明 弹出全屏显示的网页模式对话框,用户关闭之前不能浏览网站的其他内容. 技术要点 本实例主要应用screen对象的width.height属性和window对象的showModalDialog()方法实现.其实还有一种方法打开网页对话框,即showModelessDialog()方法. 使用showModalDialog()与showModelessDialog()方法的区别在于,showModalDialog

【温故而知新】Javascript窗口效果 (全屏显示窗口、定时关闭窗口)

1.全屏显示窗口 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="

Fullscreen API 全屏显示网页

第一次看到应用 Fullscreen API 全屏显示网页,是 FaceBook 中的照片放大.作为一个比较新的 API,目前只有 Safari.Chrome 和 FireFox 三种浏览器支持该特性.因为尚未发布正式版的标准,所以必须使用浏览器特定的方法,也就是应用添加前缀(webit/moz)的方法. 这个 API 不仅能够使整个页面全屏显示,也可以使页面中的某个元素全屏显示.它的设计初衷是为了全屏显示 HTML5 视频和游戏,以便更全面的替代 flash 功能.尽管还有很多有待完善的地方,

DOM元素全屏显示解决方案

<script type="text/javascript"> function goFullscreen(id) { // Get the element that we want to take into fullscreen mode var element = document.getElementById(id); // These function will not exist in the browsers that don't support fullscr

js控制页面的全屏展示和退出全屏显示

<!DOCTYPE html> <html> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <body > <button id="btn" >js控制页面的全屏展示和退出全屏显示</button> <div id="content" style="

适用于定宽和适用于全屏显示

<html> <head> <meta charset="utf-8"> <title></title> <!--引入css文件--> <link rel="stylesheet" type="text/css" href="bookstrap/css/bookstrap.css"> <!--引入jquery--> <scri

Xcode 设置图片全屏显示

- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib.// UIImage *image = [UIImage imageNamed:@"initial_page_bg.jpg" ]; UIImageView *imageView = [[UIImageView alloc]initWithImage:image

Linux 命令 - watch: 反复执行命令,全屏显示输出

watch 命令周期性地执行命令,全屏显示输出.可以通过 watch 命令反复执行某一程序来监视它的输出变化. 命令格式 watch [-dhvt] [-n <seconds>] [--differences[=cumulative]] [--help] [--interval=<seconds>] [--no-title] [--version] <command> 命令参数 -n, --interval 指定间隔时间.默认情况下,watch 每隔 2 秒执行一次命令

Android全屏显示(代码实现)

// 去掉窗口标题 requestWindowFeature(Window.FEATURE_NO_TITLE); // 全屏显示 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 注:写在activity里