本节主要讲解Windows对象中的常用对象属性,下面我们用具体实例来做详细说明。
window:
document
location 位置
<meta http-equiv="refresh" content="3">//3秒钟刷新一次
<meta http-equiv="refresh" content="3";url="http://www.baidu.com">//3秒钟跳转的baidu.com页面
header("Location:login.php");php用法,前面不能有输出
window.navigate(url)
location.href='url'
location.replace("url")
history
history.back()和history.go(-1)是等价的
history.go(-2)
screen
.......
记的:
location="url"
location.reload(ture)
例1
<html>
<head>
<meta http-equiv="refresh" content="3";url='pop.html'>
</head>
<script>
document.write(new Date()+"<br>");
</script>
</html>
例2
<html>
<head>
</head>
<script>
setTimeout(function{
//window.navigate('pop.html');
//window.location.href='pop.html';
//location='pop.html';//推荐使这种方式
location.replace('pop.html');//不能后退,把当前的页面替换成现在的页面
location.reload(true);//刷新
},3000);
document.write(new Date()+"<br>");
</script>
</html>
例3
one.html
<a gref="two.html"></a>
two.html
<a href="three.html">three</a><br>
<a href="javascript:history.back()">返回</a>
three.html
<a href="javascript:history.go(-1)">返回上一步</a><br>
<a href="javascript:history.go(-2)">返回上两步</a><br>
例4
<script>
with(document){
write("您的屏幕显示设置如下:<p>");
write("屏幕的实际高度为",screen.availHeight,"<br>");
write("屏幕的实际宽度为",screen.availWidth,"<br>");
write("屏幕的色盘深度为",screen.colorDepth,"<br>");
write("屏幕区域的高度为",screen.height,"<br>");
write("屏幕区域的宽度为",screen.width);
}
</script>
例5 //剪切板
<div id="one">
aaaaaaaaaaaaaaaaa<br>
aaaaaaaaaaaaaaaaa<br>
</div>
<input type="button" οnclick="copyc()" value="copecode">
<script>
var one=document.getElementById("one");
function copyc(){
var content=one.innerText;
window.clipboardData.setData("Text",content)//剪切板
}
</script>