JavaScrip--window对象

window对象
window对象中是javascript的核心对象,当打开一个窗口的时候
自动就生成window对象,像我们常用的document等都是window的属性
比如全局变量都是属性
比如全局函数都是方法
下面介绍两个属性:
innerwidth
innerheight
两个方法:
window.close();
window.open();
open包含了常用的几个参数,
第一个是要打开的页面,
第二个是打开窗口的名字
第三个是打开窗口的一些特征

代码如下:
<body>
<div id="divid">
    <button id="btn" onclick="display()">显示窗口的大小</button>
    <p id="pid" style="display: inline;"> </p>
</div>
<br/>
<button onclick="openwindow()">打开新的窗口</button>
<br/>
<button onclick="closewindow()">关闭窗口</button>

<script>

    function display(){
        var width=window.innerWidth;
        var height=window.innerHeight;
        var txt=""+width+","+"height:"+height;

        var pid=document.getElementById("pid");
        pid.innerHTML=txt;

        setTimeout(function(){
            pid.innerHTML="";
        },3000)

    }

    function openwindow(){
        window.open("windowtest.html","打开的测试的窗口","height=100,width=150,left=100,top=100");
    }

    function closewindow(){
        window.close();
    }
</script>
</body>

原文地址:https://www.cnblogs.com/YangMT/p/4864422.html