<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
<title>BOM</title>
<script type="text/javascript">
</script>
</head>
<body>
</body>
<script type="text/javascript">
// BOM对象就是可以对浏览器进行操作的对象
// JS里面所有的全局变量都是window对象的属性
a = 40;
console.log(window.a);
window.a = 50;
console.log(a);
// 所有的函数都是window对象的属性(成员变量)
function test() {
console.log(this);
}
window.test();
// 获取窗口高度
document.write(window.innerHeight);
document.write('<br/>');
document.write(window.innerWidth);
document.write('<br/>');
// 不同的获取屏幕高度的方法
document.write(document.documentElement.clientHeight);
document.write('<br/>');
document.write(document.body.clientHeight);
document.write('<br/>');
// 兼容不同浏览器的获取窗口高度的方法
document.write(window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight);
document.write('<br/>');
// 整体宽高包括工具栏
document.write('窗口整体宽度:' + window.outerWidth);
document.write('<br/>');
document.write('窗口整体高度:' + window.outerHeight);
window.setTimeout(function(){
// window.open
// 打开窗口
// var newWindow = open('https://www.baidu.com/','','width=100,height=100');
// 关闭窗口
// close();
// resizeTo 是把窗口调整到多少
// resizeBy 是把窗口增加多少,可以是负数代表减少
newWindow.moveTo(300, 300);
newWindow.resizeTo(100, 100);
newWindow.resizeBy(100, 100);
},2000);
document.write('<br/>');
document.write('屏幕宽度:' + screen.width + 'px<br/>');
document.write('屏幕高度:' + screen.height + 'px<br/>');
document.write('屏幕可用宽度:' + screen.availWidth + 'px<br/>');
document.write('屏幕可用高度:' + screen.availHeight + 'px<br/>');
// 显示一个确认框,在确认框内显示提示字符串,当用户单击“确定”按钮 时该方法返回true,单击“取消”时返回false。
// window.confirm('你是猪?') ;
// 显示一个输入框,在输入框内显示提示字符串,在输入文本框显示缺省文本,并等待用户输入,当用户单击“确定”按钮时,返回用户输入的字符串,当 单击“取消”按钮时,返回null值。
// window.prompt('姓名');
</script>
</html>
WEB前端 | JS基础——(8)DOM
最新推荐文章于 2024-09-22 11:17:00 发布