javascript window.history对象如何应用

发布时间:2022-08-05 11:42:04 作者:iii
来源:亿速云 阅读:93

今天小编给大家分享一下javascript window.history对象如何应用的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。

javascript window.history对象如何应用

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

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

注意: 没有应用于History对象的公开标准,不过所有浏览器都支持该对象。

javascript window.history对象如何应用

描述:页面栈对象

说明:栈区特征为(后进先出),堆区特征为(先进先出)

内容:

注意:

javascript window.history对象如何应用

     <h3>第一页</h3>
    <button class="next">去到第二页</button>
    <hr/>
    <h4>window.history对象提供的方法</h4>
    <button class="back">window.history.back()</button>
    <button class="forward">window.history.forward()</button>
    <button class="go">window.history.go(2)</button>
    <button class="length">window.history.length</button>



<script>
        var nextBut = document.querySelector('.next');
        var backBut = document.querySelector('.back');
        var forwardBut = document.querySelector('.forward');
        var goBut = document.querySelector('.go');
        var lengthBut = document.querySelector('.length');

        nextBut.onclick = function() {
            document.location.href = '11第2个页面.html';
        }
        backBut.onclick = function() {
            window.history.back()
        }
        forwardBut.onclick = function() {
            window.history.forward()
        }
        goBut.onclick = function() {
            window.history.go(2)
        }
        lengthBut.onclick = function() {
            console.log(window.history.length)
        }
</script>

javascript window.history对象如何应用

当单击“去到第二页”按钮时:

第二个页面:

<h3>第二个页面</h3>
<button  class="next">去到第三页</button>
<hr/>
<h4>window.history对象提供的方法</h4>
<button  class="back">window.history.back()</button>
<button  class="forward">window.history.forward()</button>
<button  class="go">window.history.go(2)</button>
<button  class="length">window.history.length</button>

 <script>
        var nextBut = document.querySelector('.next');
        var backBut = document.querySelector('.back');
        var forwardBut = document.querySelector('.forward');
        var goBut = document.querySelector('.go');
        var lengthBut = document.querySelector('.length');

        nextBut.onclick = function() {
            document.location.href = '11第3个页面.html';
        }
        backBut.onclick = function() {
            window.history.back()
        }
        forwardBut.onclick = function() {
            window.history.forward()
        }
        goBut.onclick = function() {
            window.history.go(2)
        }
        lengthBut.onclick = function() {
            console.log(window.history.length)
        }
</script>

当单击”去到第三页“按钮时:

javascript window.history对象如何应用

当然,底下的几个按钮都可以点击,感兴趣的自己动手试试,然后进行尝试!

第三个页面:

<h3>第三个页面</h3>
<button  class="next">去到第四页</button>
<hr/>
<h4>window.history对象提供的方法</h4>
<button  class="back">window.history.back()</button>
<button  class="forward">window.history.forward()</button>
<button  class="go">window.history.go(2)</button>
<button  class="length">window.history.length</button>

 <script>
        var nextBut = document.querySelector('.next');
        var backBut = document.querySelector('.back');
        var forwardBut = document.querySelector('.forward');
        var goBut = document.querySelector('.go');
        var lengthBut = document.querySelector('.length');

        nextBut.onclick = function() {
            document.location.href = '11第4个页面.html';
        }
        backBut.onclick = function() {
            window.history.back()
        }
        forwardBut.onclick = function() {
            window.history.forward()
        }
        goBut.onclick = function() {
            window.history.go(2)
        }
        lengthBut.onclick = function() {
            console.log(window.history.length)
        }
</script>

效果图如下:当单击”去到第四页“按钮时:

javascript window.history对象如何应用

第四个页面:

     <h3>第四个页面</h3>
    <button class="next">回到首页</button>
    <hr/>
    <h4>window.history对象提供的方法</h4>
    <button class="back">window.history.back()</button>
    <button class="forward">window.history.forward()</button>
    <button class="go">window.history.go(2)</button>
    <button class="length">window.history.length</button>

<script>
        var nextBut = document.querySelector('.next');
        var backBut = document.querySelector('.back');
        var forwardBut = document.querySelector('.forward');
        var goBut = document.querySelector('.go');
        var lengthBut = document.querySelector('.length');

        nextBut.onclick = function() {
            document.location.href = '11window.history对象.html';
        }
        backBut.onclick = function() {
            window.history.back()
        }
        forwardBut.onclick = function() {
            window.history.forward()
        }
        goBut.onclick = function() {
            window.history.go(2)
        }
        lengthBut.onclick = function() {
            console.log(window.history.length)
        }
</script>

效果图如下:当单击”回到首页“按钮时:

javascript window.history对象如何应用

以上就是“javascript window.history对象如何应用”这篇文章的所有内容,感谢各位的阅读!相信大家阅读完这篇文章都有很大的收获,小编每天都会为大家更新不同的知识,如果还想学习更多的知识,请关注亿速云行业资讯频道。

推荐阅读:
  1. javascript-浏览器对象
  2. HTML5 History对象,Javascript修改地址栏而不刷新页面

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

javascript

上一篇:win10如何删除头像记录

下一篇:HTML内联标签iframe如何使用

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》