function onPopstate(e) {
updatePopStateReceivedText(true);
const stateText = e.state ? e.state : '(NO STATE OBJECT)';
updateStateObjectText(stateText);
}
function onHashChange(e) {
updateHashChangeReceivedText(true);
}
function updateOnLoadText(text) {
document.getElementById('on-load-div').innerHTML = text;
}
function updateNoOpText(text) {
document.getElementById('no-op-div').innerHTML = text;
}
function updatePopStateReceivedText(received) {
const text = received ? 'PopStateReceived' : '';
document.getElementById('pop-state-received-div').innerHTML = text;
}
function updateStateObjectText(state) {
document.getElementById('state-object-div').innerHTML = state;
}
function updateHashChangeReceivedText(received) {
const text = received ? 'HashChangeReceived' : '';
document.getElementById('hash-change-received-div').innerHTML = text;
}
function onButtonTapped() {
updateOnLoadText('');
updateNoOpText('');
updatePopStateReceivedText(false);
updateStateObjectText('');
updateHashChangeReceivedText(false);
setTimeout('updateNoOpText(\'NoOpText\')', 1000);
}
function goNoParameter() {
onButtonTapped();
window.history.go();
}
function goZero() {
onButtonTapped();
window.history.go(0);
}
function goBack() {
onButtonTapped();
window.history.back();
}
function goForward() {
onButtonTapped();
window.history.forward();
}
function go2() {
onButtonTapped();
window.history.go(2);
}
function goBack2() {
onButtonTapped();
window.history.go(-2);
}
function pushStateWithHash() {
onButtonTapped();
window.history.pushState('STATE_OBJECT', 'Title', '#hash');
}
window.onload = function() {
window.addEventListener('popstate', onPopstate);
window.addEventListener('hashchange', onHashChange);
updateOnLoadText('OnLoadText');
};