window object properties and methods

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

  • ##document.documentElement is< ;html> mark object

  • document.body is <body> mark object

  • <!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

  • alert(): Pops up a warning dialog box.

  • prompt(): Pops up an input dialog box.

  • confirm(): Pops up a confirmation dialog box. Returns true if the OK button is clicked and false if Cancel is clicked.

  • close(): Close the window

  • print(): Print the window

  • <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8" />
    <title>php.cn</title>
    <script>
        function delect() {
            if(window.confirm("你确认要删除吗?")){
                //跳转到指定删除页面执行删除操作
               location.href="http://www.php.cn";   
            }     
        }
    </script>
    </head>
    <body>
        <a href="#" onClick="delect()">删除</a>
    </body>
    </html>
Continuing Learning
||
<!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>
submitReset Code