Window对象常用属性和方法
(1)简单对话框:alert()、confirm()和prompt();
<html> <head> <title>简单对话框</title> </head> <body> <script> var yourname = prompt("您的名字是:"); //console.log(yourname); if(confirm("您确定吗?")==true) { alert(yourname+"先生,你好"); } </script> </body> </html>
运行结果:
(2)状态栏:status属性和defaultStatus属性;(一般不支持用,这里就不说了)
(3)定时设定和时间间隔:setTimeout()、clearTimeout()、setlterval()、clertlnterval();
<html> <head> <title>定时设定和时间间隔</title> </head> <body> <script type="text/javascript"> function display() { var content = document.getElementById("text"); content.value= new Date().toLocaleString(); } window.onload=function() { var timer; document.getElementById("start").onclick=function() { timer = setInterval(‘display()‘,1000); } document.getElementById("stop").onclick=function() { clearInterval(timer); } } </script> <input type="text" value="" id="text" size=30/> <input type="button" value="开始" id="start" /> <input type="button" value="结束" id="stop" /> </body> </html>
运行结果如下:
(4)navigator:用于获取浏览器和操作系统的信息;
(5)Screen对象:有关用户显示器的大小和可用的颜色数量信息;
<html> <head> <title>navigator对象和Screen对象</title> </head> <body> <input type="button" id="demo1" value="显示浏览器信息"/> <input type="button" id="demo2" value="显示屏幕信息"/> <script type="text/javascript"> document.getElementById("demo1").onclick= function() { alert ( "浏览器信息:\n"+ "名称:"+navigator.appName+"\n"+ "平台和版本:"+navigator.appVersion+"\n"+ "操作系统:"+navigator.platform+"\n"+ "userAgent"+navigator.userAgent ); } document.getElementById("demo2").onclick= function() { alert ( "屏幕信息:\n"+ "分辨率:"+screen.width+"*"+screen.height+"\n"+ "可用区域"+screen.availWidth+"*"+screen.availHeight ); } </script> </body> </html>
运行结果如下:
原文:https://www.cnblogs.com/daitu/p/12772685.html