zoukankan      html  css  js  c++  java
  • JS的history对象和location对象

    History 对象

    History 对象属性

    History 对象包含用户(在浏览器窗口中)访问过的 URL。

    History 对象是 window 对象的一部分,可通过 window.history 属性对其进行访问。

    length  返回浏览器历史列表中的 URL 数量。

    History 对象方法

    back()    加载 history 列表中的前一个 URL。
    forward()    加载 history 列表中的下一个 URL。
    go()    加载 history 列表中的某个具体页面。
    <a href="rrr.html">click</a>
    <button onclick=" history.forward()">>>></button>
    <button onclick="history.back()">back</button>
    <button onclick="history.go()">back</button>

    Location 对象

    Location 对象包含有关当前 URL 的信息。

    Location 对象是 Window 对象的一个部分,可通过 window.location 属性来访问。

    Location 对象方法

    location.assign(URL)
    location.reload()
    location.replace(newURL) //注意与assign的区别
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>标题</title>
    </head>
    <body>
        <!--History对象-->
        <!--<a href="day125_1.html">click</a>-->
        <!--<button onclick="history.forward()">》》》</button>-->
        <!--先让a标签跳到另一个页面,back返回,forward回到跳转页面;forward与back相对应-->
    
        <!--<button onclick="history.go(1)">》》》》》》</button>-->
        <!--go与go相对应,一个是1一个是-1即可-->
    
    
        <button onclick="f()">click</button>
        <script>
            // location对象
            function f() {
                // location.assign('https://www.baidu.com'); // 跳转到指定URL,还可以操作浏览器进行返回之前页面
                // location.reload(); // 刷新当前页面
                // location.replace('https://www.baidu.com'); // 跳转到指定URL,但是无法进行返回之前页面(替换)
            }
        </script>
    </body>
    </html>
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
        <!--History对象-->
        <!--<button onclick="history.back()">back</button>-->
        <!--<button onclick="history.go(-1)">back</button>-->
    </body>
    </html>
    while True: print('studying...')
  • 相关阅读:
    php获取真实ip地址原理及实现
    关于DateTime计算某个日期过后的多少天之后的日期
    关于get_include_path()和set_include_path()的问题
    LinQ In Action 学习第三章
    LinQ In Action 学习第二章
    LinQ in Action 学习第一章 例子。
    asp.net create windows application and setup service.
    JS alert()、confirm()、prompt()的区别
    php获取用户 地区 、ip地址
    购物车相关 js
  • 原文地址:https://www.cnblogs.com/xuewei95/p/15018887.html
Copyright © 2011-2022 走看看