Window object properties
First, loop through all the properties of the window object:
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>php.cn</title> <script> //循环遍历window对象的所有属性 /* for(name|index in obj|arr){ } 描述:只能循环数组的下标,或对象的属性。 说明:如果循环数组的话,每次循将取下标值。 对于数组中值为undefined的,不会循环。 循环数组,只返回有效的值。 如果循对象的话,每次循环取对象属性。 严格的来说,对象中没有方法一说,所有的都是属性。 将一个函数赋给一个属性后,这个属性就变成方法了。 */ var i = 1; for(var name in window) { document.write(i+" "+name+"<br>"); i++; } </script> </head> <body> </body> </html>
name : Refers to the name of the browser window or frame. This name is used for the target attribute of the a tag.
Set the name of the window: window.name = “newWin”
Get the name of the window: document.write (name);
top: Represents the top-level window. For example: window.top
parent: represents the parent window, mainly used for frames.
self: represents the current window, mainly used in frames.
innerWidth: refers to the inner width of the browser window (excluding menu bar, toolbar, address bar, status bar). This attribute is supported by Firefox.
Under IE, use document.documentElement.clientWidth instead of window.innerWidth
innerHeight: refers to the inner height of the browser window (excluding menu bar, toolbar, address bar, status bar). This attribute is supported by Firefox.
Under IE, use document.documentElement.clientHeight instead of window.innerHeight
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>php.cn</title> <script> //实例:测试当前网页的宽度和高度 //兼容所有浏览器 var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth; var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight; //输出结果 document.write("宽度:"+width+",高度:"+height); </script> </head> <body> </body> </html>window object method
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>php.cn</title> <script> function delect() { if(window.confirm("你确认要删除吗?")){ //跳转到指定删除页面执行删除操作 location.href="//m.sbmmt.com"; } } </script> </head> <body> <a href="#" onClick="delect()">删除</a> </body> </html>Next Section