BOM中window简介

一、BOM-window简介

①window.location.href和window.location.assign均可跳转页面,支持回退

②window.location.replace可以跳转页面,不支持回退

③window.location.reload刷新页面,传入参数true时,强制刷新,不留缓存

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <title>BOM window</title>

    <style>

        body {

            background-color : red;

        }

    </style>

</head>

<body>

<button οnclick="href()"> 跳转 </button>

<button οnclick="refresh()"> 刷新 </button>

<button οnclick="func()"> 加载 </button>

<button οnclick="repl()"> repl</button>

<script>

    // BOM 对象 document

    document.write("<br/>");

    document.write(window.document);

    document.write("<br/>");

    // 展示 当前页面中的所有框架的集合

    document.write(window.frames);

    document.write("<br/>");

    // 用于反应浏览器及其功能的对象

    document.write(window.navigator);

    document.write("<br/>");

    // 提供浏览器以外的环境信息

    document.write(window.screen);

    document.write("<br/>");

    // window.location

    // 跳转页面

    function href() {

        window.location.href = "js_math_demo.html";

    }

    // 刷新,可穿参数true,强制刷新不留缓存

    function refresh(){

        window.location.reload();

    }

    // assign()

    // 加载新的页面

    function func(){

        window.location.assign("js_math_demo.html");

    }

    // 加载新页面,不能回退

    function repl(){

        window.location.replace("js_math_demo.html");

    }

</script>

</body>

</html>

二、window.history对象

①获取历史长度window.history.length

②下一页window.history.forward

③上一页window.history.back

④跳转至指定页面window.history.go,是正数时前进,是负数时后退

三、window函数及事件

Ⅰ函数

①打开新窗口open

②关闭当前窗口close

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <title>BOM window 函数</title>

</head>

<body>

<button οnclick="openWindow()"> 打开新窗口 </button>

<button οnclick="closeWindow()"> 关闭当前窗口 </button>

<script>

    // open

    function openWindow(){

        window.open("BOM_window_demo.html","blank","width=200px, height=200px, top=10px, left=10px");

    }

    // close

    function closeWindow(){

        window.close();

    }

</script>

</body>

</html>

Ⅱ事件

①onload 加载事件:页面加载完成后自动触发

②onscroll 滚动事件

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <title>window 事件</title>

    <style>

        body {

            height : 3000px;

        }

    </style>

</head>

<body>

<script>

    // 事件

    // onload 加载事件:页面完成加载后自动触发

    window.onload = function(){

        document.write("hello");

    }

    // onscroll 滚动事件

    window.onscroll = function (){

       var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;

       console.log(scrollTop);

    }

</script>

</body>

</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值