S
S
sasmoney2021-12-20 21:05:09
AJAX
sasmoney, 2021-12-20 21:05:09

How to execute the past function on clicking back in the browser?

Basically, there is this code:

.d-none {display:none}

<div id="main">Index page</div>
<div id="faq" class="d-none">Index page</div>

<li><a href="/" onclick="mainh()">Главная</a></li>
<li><a href="/faq" onclick="faqh()">FAQ</a></li>


Its functions:
function mainh(){
$('#main').removeClass('d-none');
$('#faq').addClass('d-none');

event.preventDefault();
history.pushState(null, null, '/');
$('title').text('NameSite - Index');
}
function faqh(){
$('#main').addClass('d-none');
$('#faq').removeClass('d-none');

event.preventDefault();
history.pushState(null, null, '/faq');
$('title').text('NameSite - FAQ');
}


In general, everything works, but how, when clicking on "back" in the browser, return the user to the previous function, since at the moment only the url in the browser line changes, and the functions are not executed

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Arman, 2021-12-20
@sasmoney

https://developer.mozilla.org/ru/docs/Web/API/Wind...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question