Class History
- Namespace
- CSharpToJavaScript.APIs.JS
- Assembly
- CSharpToJavaScript.dll
The History interface of the {{domxref("History API", "", "", "nocode")}} allows manipulation of the browser session history, that is the pages visited in the tab or frame that the current page is loaded in.
[Value("History")]
public class History
- Inheritance
-
History
- Inherited Members
Remarks
There is only one instance of history (It is a singleton.) accessible via the global object History.
NOTE
This interface is only available on the main thread (Window). It cannot be accessed in Worker or Worklet contexts.
-History global object
Constructors
History()
public History()
Properties
Length
The length read-only property of the History interface
returns an integer representing the number of entries in the session
history, including the currently loaded page.
[Value("length")]
public ulong Length { get; }
Property Value
- ulong
A number.
Remarks
For example, for a page loaded in a new tab this property returns 1.
-The History interface it belongs to.
ScrollRestoration
The scrollRestoration property of the History
interface allows web applications to explicitly set default scroll restoration behavior
on history navigation.
[Value("scrollRestoration")]
public ScrollRestoration ScrollRestoration { get; set; }
Property Value
- ScrollRestoration
One of the following:
Remarks
State
The state read-only property of the History interface
returns a value representing the state at the top of the history stack. This is
a way to look at the state without having to wait for a Windowpopstate event.
[Value("state")]
public dynamic State { get; }
Property Value
- dynamic
The state at the top of the history stack. The value is
nulluntil the
PushState(dynamic, string, string?) or
ReplaceState(dynamic, string, string?) method is used.
Remarks
Methods
Back()
The back() method of the History interface causes
the browser to move back one page in the session history.
[Value("back")]
public GlobalObject.Undefined Back()
Returns
Remarks
It has the same
effect as calling Go(long). If there is no previous
page, this method call does nothing.
This method is asynchronous. Add a listener for the
Windowpopstate event in order to determine when the navigation has completed.
Forward()
The forward() method of the History interface causes the browser to move
forward one page in the session history. It has the same effect as calling
Go(long).
[Value("forward")]
public GlobalObject.Undefined Forward()
Returns
Remarks
This method is {{glossary("asynchronous")}}. Add a listener for the Windowpopstate event in order to determine when the navigation has completed.
-History
-Windowpopstate
-Working with the History API
Go(long)
The go() method of the History interface loads a specific page from the
session history. You can use it to move forwards and backwards through the history
depending on the value of a parameter.
[Value("go")]
public GlobalObject.Undefined Go(long delta = 0)
Parameters
deltalong
Returns
Remarks
This method is asynchronous. Add a listener for the
Windowpopstate event in order to determine when the navigation has completed.
-History
-Back()
-Forward()
-Windowpopstate event
-Working with the History API
PushState(dynamic, string, string?)
The pushState() method of the History interface adds an entry to the browser's
session history stack.
[Value("pushState")]
public GlobalObject.Undefined PushState(dynamic data, string unused, string? url = null)
Parameters
Returns
Remarks
ReplaceState(dynamic, string, string?)
The replaceState() method of the History interface modifies the current
history entry, replacing it with the state object and
URL passed in the method parameters. This method is particularly useful
when you want to update the state object or URL of the current history entry in response
to some user action.
[Value("replaceState")]
public GlobalObject.Undefined ReplaceState(dynamic data, string unused, string? url = null)