当前位置:网站首页>Jump without refresh - detailed explanation of pushstate and replacestate methods in history

Jump without refresh - detailed explanation of pushstate and replacestate methods in history

2022-06-11 02:05:00 Bejpse

〝 The ancients lost their knowledge , Kung Fu begins when you are young and when you are old 〞

** About history in pushState and replaceState Methods, ,** Often codewords are not easy , It's more difficult to produce high-quality products , Not particularly lucky , Then please make special efforts first , Don't fail because of laziness , And hypocritically attributed the reason to his bad luck . You have to work very hard , To appear effortless . If this article can help you a little , Hope to give little brother flying rabbit one key three times , Express support , Thank you guys .

Catalog

One 、 Method function

Two 、 Parameters,

3、 ... and 、 The two are the same

Four 、 Differences between the two


One 、 Method function

  • HTML5 The new interface , You can change the URL without refreshing the page
  • There are cross-domain problems , Rewriting to another domain name is not supported
  • Just change the URL , Web pages don't really jump , And you won't get new content , In essence, the web page still stays on the original page

Two 、 Parameters,

  • window.history.pushState( data, title, url )
  • data State object : Information to the destination route , May be empty
  • title The page title : Currently, all browsers don't support , Fill in the blank string
  • url Optional url: The goal is url, Will not check url Whether there is , And not across domains . If you don't pass on the item , Give the current url add to data

  • window.history.replaceState( data, title, url )
  • data State object : Information to the destination route , May be empty
  • title The page title : Currently, all browsers don't support , Fill in the blank string
  • url Optional url: The goal is url, Will not check url Whether there is , And not across domains . If you don't pass on the item , Give the current url add to data
  • Be similar to pushState, But it will replace the current url, Not in history Leave a record in the book

3、 ... and 、 The two are the same

  • Can be modified without refresh url
  • Does not support cross domain , That is, it does not support the modification of records into other domain names
  • For example, I am under Baidu domain name , I want to c Put the domain name of the station into the history

Four 、 Differences between the two

  • Whether the record will be left , The meaning of this sentence is to change url after , Is it ok to pass back retracement
  • pushState Because leave a record , So you can go back
  • replaceState Because there is no record left , So you can't return

原网站

版权声明
本文为[Bejpse]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203020620444097.html