zoukankan      html  css  js  c++  java
  • history replaceState/pushState

    HTML5 history新增了两个属性,分别是replaceState()和pushState(),不刷新页面改变页面的url。

    replaceState()可以不让页面刷新的情况下改变url

    用法:history.replaceState("data","页面的title","变化后的url")

    <body>
    	<input type="button" value="按钮" id="btn">
    </body>
    <script>
    	$('#btn').click(function(){
    		history.replaceState(null,"title","aa.html?name=12345");
    		history.replaceState(null,"title","bb.html?name=67890");
    	})
    </script>

    ps:经测试有些页面的title是无法改变的

    pushState()是在浏览器历史中插入一条url的记录,后插入的会在记录(数组)的最顶端,同理replaceState可以让页面不刷新改变url,区别是可以通过浏览器返回到上一个记录的url,优点是在ajax局部渲染页面后可以通过浏览器返回按钮返回到渲染前的记录

    用法:history.pushState("data","页面的title","变化后的url")

    <body>
    	<input type="button" value="按钮" id="btn">
    </body>
    <script>
    	$('#btn').click(function(){
    		history.pushState(null,"title","aa.html?name=12345");
    		history.pushState(null,"title","bb.html?name=67890");
    	})
    </script>
    

      

  • 相关阅读:
    3. What’s New in Spring Security 4.2 spring security 4.2的新功能
    2. Introduction介绍
    1. Getting Started入门
    32. CAS Authentication
    Java序列化
    hive优化--数据倾斜优化
    hive优化之——控制hive任务中的map数和reduce数
    maven中引入jstl
    redis位操作
    Windows单机安装hadoop
  • 原文地址:https://www.cnblogs.com/smartyu/p/5177655.html
Copyright © 2011-2022 走看看