zoukankan      html  css  js  c++  java
  • pushState,replaceState无刷新改变url

    pushState和replaceState可以做到改变网址却不需要刷新页面。

    1. pushState

    说明:浏览器会记录pushState的历史记录,可以使用浏览器的前进、后退功能作用,可以使用history.go(-1)返回到上一个页面

    使用方法:window.history.pushState(state, title, url)

    参数说明:

    state: 一个与指定网址相关的状态对象,popstate事件触发时,该对象会传入回调函数。如果不需要这个对象,此处可以填null
    title: 新页面的标题,但是所有浏览器目前都忽略这个值,因此这里可以填null
    url: 新的网址,必须与当前页面处在同一个域,浏览器的地址栏将显示这个网址

    2. replaceState

    说明:replaceState仅仅是修改了对应的历史记录,replaceState不会加入到历史记录里面,用history.go(-1)会跳过当前页面相当于是history.go(-2)

    使用方法:window.history.replaceState(state, title, url)

  • 相关阅读:
    平时十六测
    平时十五测
    平时十四测
    poj 1486 Sorting Slides
    POJ 3621Sightseeing Cows
    POJ 2728 Desert King
    POJ3111 K Best
    NOIopenjudge 407:Heritage
    POJ#2065. SETI
    HDU 4607 Park Visit
  • 原文地址:https://www.cnblogs.com/juewuzhe/p/12851550.html
Copyright © 2011-2022 走看看