JS浏览器对象

window.document.write("width"+window.innerWidth+"height"+window.innerHeight);

不包括框的宽度

打开网页:

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
    <button id="btn" οnclick="btnClicked()">button</button>
    <script>
        //window.document.write("width"+window.innerWidth+"height"+window.innerHeight);
        function btnClicked(){
            window.open("openhtml.html");
        }
    </script>
</body>
</html>
加参数:

window.open("openhtml.html","windowname","height=200,weight=200,top=100,left=100,toolbar=no,menubar=no");

关闭窗口:

window.close();

window对象很多对象的祖先~~

计时器:


开始与停止

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
    <button id="btn" οnclick="stopTime()">button</button>
    <p id="ptime"></p>
    <script>
        var mytime=setInterval(function(){
            getTime();
        },1000);
        function getTime(){
            var d=new Date();
            var t= d.toLocaleTimeString();
            document.getElementById("ptime").innerHTML=t;
        }
        function stopTime(){
            clearInterval(mytime);
        }
    </script>
</body>
</html>

延迟执行:

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
    <button id="btn" οnclick="mywin()">button</button>
    <p id="ptime"></p>
    <script>
        var min;
        function mywin(){

            win=setTimeout(function(){alert("hello");},3000);

        }
    </script>
</body>
</html>
一直执行:

var min;
        function mywin(){
            alert("hello");
            win=setTimeout(function(){mywin()},3000);

        }

暂停:

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body οnlοad="myWin()">
    <button id="btn" οnclick="stopWin()">button</button>
    <p id="ptime"></p>
    <script>
        var min;
        function myWin(){
            alert("hello");
            win=setTimeout(function(){myWin()},3000);

        }
        function stopWin(){
            clearTimeout(win);
        }
    </script>
</body>
</html>

历史:

foward:/back:

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
    <button οnclick="goceshi()">button</button>
    <script>
        function goceshi(){
            history.back();
        }
    </script>
</body>
</html>

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
    <a href="openhtml.html">back to index</a>
    <button id="btn" οnclick="goob()">button</button>
    <script>
        function goob(){
            history.forward();
        }
    </script>
</body>
</html>


<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
    <button id="btn" οnclick="getLoc()">button</button>
    <p id="ptime"></p>
    <script>
        function getLoc(){
           document.getElementById("ptime").innerHTML= window.location.hostname;
        }
    </script>
</body>
</html>
返回: localhost

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
    <button id="btn" οnclick="getLoc()">button</button>
    <p id="ptime"></p>
    <script>
        function getLoc(){
           document.getElementById("ptime").innerHTML= window.location.pathname;
        }
    </script>
</body>
</html>

返回:
/untitled1/ceshi.html
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
    <button id="btn" οnclick="getLoc()">button</button>
    <p id="ptime"></p>
    <script>
        function getLoc(){
           document.getElementById("ptime").innerHTML= window.location.port;
        }
    </script>
</body>
</html>

返回:63342(端口)

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
    <button id="btn" οnclick="getLoc()">button</button>
    <p id="ptime"></p>
    <script>
        function getLoc(){
           document.getElementById("ptime").innerHTML= window.location.href;
        }
    </script>
</body>
</html>


返回地址: http://localhost:63342/untitled1/ceshi.html

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
    <button id="btn" οnclick="getLoc()">button</button>
    <p id="ptime"></p>
    <script>
        function getLoc(){
           location.assign("http://www.jikexueyuan.com");
        }
    </script>
</body>
</html>

用来做屏幕适配:

        document.write("可用高度:"+screen.availHeight+",可用高度"+screen.availWidth);
        document.write("高度"+screen.height+"宽度:"+screen.width);


输出:可用高度:768,可用高度1304高度768宽度:1366

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值