Window 对象
所有浏览器都支持 window 对象。它表示浏览器窗口。
所有 JavaScript 全局对象、函数以及变量均自动成为 window 对象的成员。
全局变量是 window 对象的属性。
全局函数是 window 对象的方法。
甚至 HTML DOM 的 document 也是 window 对象的属性之一:
window.document.getElementByID("header");
与此相同:
document.getElementByID("header");
Window 尺寸
有三种方法能够确定浏览器窗口的尺寸(浏览器的视口,不包括工具栏和滚动条)。
对于Internet Explorer、Chrome、firefox、Opera 以及 Safari:
对于 Internet Explorer 8、7、6、5:
document.documentElement.clIEntHeight document.documentElement.clIEntWIDth或者
document.body.clIEntHeight document.body.clIEntWIDth实用的 JavaScript 方案(涵盖所有浏览器):
实例
var w=window.innerWIDth|| document.documentElement.clIEntWIDth|| document.body.clIEntWIDth;var h=window.innerHeight|| document.documentElement.clIEntHeight|| document.body.clIEntHeight;
该例显示浏览器窗口的高度和宽度:(不包括工具栏/滚动条)
Window Screen
window.screen对象在编写时可以不使用 window 这个前缀。
一些属性:
实例
返回您的屏幕的可用宽度:
<script>document.write("Available WIDth: " + screen.availWIDth);</script>
以上代码输出为:
Available WIDth: 1440
Window Screen 可用高度
screen.availHeight 属性返回访问者屏幕的高度,以像素计,减去界面特性,比如窗口任务栏。
实例
返回您的屏幕的可用高度:
<script>document.write("Available Height: " + screen.availHeight);</script>
以上代码将输出:
Available Height: 860总结
以上是内存溢出为你收集整理的详解JavaScript编程中的window与window.screen对象全部内容,希望文章能够帮你解决详解JavaScript编程中的window与window.screen对象所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)