javaScript Window对象

Window 对象
所有浏览器都支持 window 对象。它表示浏览器窗口。
所有 JavaScript 全局对象、函数以及变量均自动成为 window 对象的成员。
全局变量是 window 对象的属性。
全局函数是 window 对象的方法。
甚至 HTML DOM 的 document 也是 window 对象的属性之一:
window.document.getElementById("header");
document.getElementById("header");

Window 尺寸
有三种方法能够确定浏览器窗口的尺寸(浏览器的视口,不包括工具栏和滚动条)。
对于Internet Explorer、Chrome、Firefox、Opera 以及 Safari:
window.innerHeight - 浏览器窗口的内部高度
window.innerWidth - 浏览器窗口的内部宽度
对于 Internet Explorer 8、7、6、5:
document.documentElement.clientHeight
document.documentElement.clientWidth
或者
document.body.clientHeight
document.body.clientWidth

var w=window.innerWidth
|| document.documentElement.clientWidth
|| document.body.clientWidth;

var h=window.innerHeight
|| document.documentElement.clientHeight
|| document.body.clientHeight;

function getWindosHeightAndWeight(){
var width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
var height = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
alert("浏览器当前的宽度是:" + width);
alert("浏览器当前的高度是:" + height);
}



Location 对象
     function getWindosHeightAndWeight(){
document.write("url:" +location.href + "<br>");
document.write("域名:" +location.hostname + "<br>");
document.write("请求文件的路径:" +location.pathname + "<br>");
document.write("端口号:" +location.port + "<br>");
document.write("协议:" +location.protocol + "<br>");
//把当前的页面跳转到百度首页上去
// location.href = "http://www.baidu.com";
// window.location.assign方法的作用相当于上句修改location的href属性
window.location.assign("http://www.baidu.com");
//下面的语句是不会执行的,因为页面已经跳转到了百度页面
alert(window.location.assign);
}



history对象
history.back() - 与在浏览器点击后退按钮相同
history.forward() - 与在浏览器中点击按钮向前相同

<html>
<head>
<script type="text/javascript">
function goBack(){
window.history.back();
}
function goFoward(){
window.history.forward();
}
</script>
</head>
<body>
<input type="button" value="goBack" onclick="goBack();">
<input type="button" value="goFoward" onclick="goFoward();">
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值