当前位置:网站首页>History object

History object

2021-01-23 20:06:52 WindrunnerMax

History object

History Object allows you to manipulate the browser's session history that has been accessed in a tab or frame .

attribute

  • history.length: read-only , Returns an integer , This integer represents the number of elements in the session history , Include the currently loaded page , For example, in a page loaded with a new tab , This property returns 1.
  • history.scrollRestoration: allow Web The application explicitly sets the default scrolling recovery behavior on the history navigation , This property can be automatic auto Or manual manual.
  • history.state read-only , Returns a value representing the state at the top of the history stack , It's a way of not having to wait popstate The way to view the state of events .

Method

  • history.back(): history.back() Go to the previous page in browser history , The user can click back in the upper left corner of the browser Button simulates this method , Equivalent to history.go(-1), Calling this method when the browser session history is on the first page has no effect , And there's no mistake .
  • history.forward(): history.forward() Go to the next page in browser history , Users can click forward in the upper left corner of the browser Button simulates this method , Equivalent to history.go(1), When the browser history stack is at the top , Calling this method when the current page is on the last page has no effect and no error .
  • history.go(): history.go(N) Load the page from the browser history, or session record, by the relative position of the current page , For example, the parameter is -1 On the previous page , Parameter is 1 It's the next page , When an integer parameter is out of bounds , For example, if the current page is the first , There are no more pages ahead , In this case, if the value of the parameter is -1, Then this method has no effect and will not report an error , Call... Without parameters go() Methods or arguments that are not integers have no effect , This is the same as supporting strings as url Parametric IE It's a little different .
  • history.pushState(): history.pushState(state, title[, url]) This method adds a state to the history stack of the current browser session state, It's named and URL( If this parameter is provided ) Put the data push Enter the conversation history stack , The data is DOM Make it opaque , You can specify anything that can be serialized JavaScript object .
  • history.replaceState(): history.replaceState(stateObj, title[, url]) This method modifies the current history entity , According to the specified data 、 Name and URL( If this parameter is provided ), Update the latest entry on the history stack , This data is DOM It's opaque , You can specify anything that can be serialized JavaScript object .

A daily topic

https://github.com/WindrunnerMax/EveryDay

Reference resources

https://developer.mozilla.org/zh-CN/docs/Web/API/History

版权声明
本文为[WindrunnerMax]所创,转载请带上原文链接,感谢
https://chowdera.com/2021/01/20210123200601072d.html

随机推荐