打开、关闭窗口
- write
<body>
<input type="button" value="write" onclick="document.write('abc')" />
</body>
- open:打开一个新窗口
<input type="button" value="打开窗口" onclick="window.open('http://www.zhinengshe.com/');" />
- close:关闭浏览器打开的新窗口
<input type="button" value="close" onclick="window.close();" />
常用属性
- window.navigator.userAgent:查看浏览器/操作系统的版本
<script>
alert(window.navigator.userAgent);
</script>
- window.location:查看文本的地址
<script>
alert(window.location);
</script>
尺寸及坐标
-
可视区尺寸
------document.documentElement.clientWidth
------document.documentElement.clientHeight -
滚动距离
------document.body.scrollTop
------document.documentElement.scrollTop
常用方法和事件
系统对话框
-
警告框:alert(“内容”),没有返回值
-
选择框:confirm(“提问的内容”),返回boolean
点确定,返回true
点取消或关闭,返回false
<script>
var res=confirm('你是否要删除');
alert(res);
//点确定,返回true
//点取消或关闭,返回false
</script>
- 输入框:prompt(),返回输入的字符串或null
<script>
//标题,暂存内容
var res=prompt('请输入你的姓名', 'blue');
alert(res);
</script>
window对象常用事件
- onload:加载
- onscroll:滚动
- onresize:改变大小
例子:右下角悬浮框
<style>
#div1 {width:200px; height:150px; background:red; position:absolute; right:0; bottom:0;}
body {height:2000px;}
</style>
<script>
window.onscroll=window.onresize=function ()
{
var scrollTop=document.documentElement.scrollTop||document.body.scrollTop;
var oDiv=document.getElementById('div1');
oDiv.style.top=document.documentElement.clientHeight-oDiv.offsetHeight+scrollTop+'px';
};
</script>
</head>
<body>
<div id="div1"></div>
</body>