History.state

번역이 완료되지 않았습니다. Please help translate this article from English

History.state 속성은 현 history에 해당하는 state값을 나타냅니다.

popstate 이벤트가 트리거될때가 아닌 상태에서 state값을 볼 수 있는 방법입니다.

문법

const currentState = history.state

현 history에 위치한 값입니다. 이 값은 pushState() 또는 replaceState()을 사용할때까지 null 값을 가집니다.

예제

history.state 로 초기값을 보여준 후 pushState()를 사용하여 State를 푸시합니다.

다음 코드 줄은 history.state 를 사용하여 콘솔에다 값이 푸시되었음을 보여줍니다.

// Should be null because we haven't modified the history stack yet
console.log(`History.state before pushState: ${history.state}`);

// Now push something on the stack
history.pushState({name: 'Example'}, "pushState example", 'page3.html');

// Now state has a value.
console.log(`History.state after pushState: ${history.state}`);

SpecificationsE

Specification Status Comment
HTML Living Standard
The definition of 'History.state' in that specification.
Living Standard
HTML5
The definition of 'History.state' in that specification.
Recommendation Initial definition.

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
stateChrome Full support YesEdge Full support 12Firefox Full support YesIE Full support 10Opera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes

Legend

Full support  
Full support

See also