Я работаю на сайте, который управляет, следующим образом:Как включить кнопку назад на АЯКС странице
$(document).ready(function() {
if (!$('#ajax').length) { // Check if index.html was loaded. If not, navigate to index.html and load the hash part with ajax.
document.location = document.location.href.substring(0, document.location.href.lastIndexOf('/') + 1)
+ "#" + document.location.href.substr(document.location.href.lastIndexOf('/') + 1);
}
if (window.location.hash) // Check if the page is being loaded with a '#'. Load the file.
$('#ajax').load(document.location.href.substr(document.location.href.lastIndexOf('#') + 1));
});
$(document).on("click", "a:not(.regular)", function (e) {
var url = this.href;
if (url.indexOf("https") != -1 || url.indexOf('.html') == -1) // External link or picture
return;
e.preventDefault();
$('#ajax').load(url, function() {
document.location.href = '#' + url.substr(url.lastIndexOf('/') + 1);
});
});
$(window).on('popstate', function (e) {
// Back only!
//location.reload();
//$('#ajax').load(this.location);
});
URL-адрес меняется, когда пользователь перемещается, даже когда пользователь нажимает на кнопку назад. Тем не менее, страница не обновляется при навигации, поэтому изменяется только URL-адрес, пока фактическая страница остается неизменной.
Как это исправить?
Fiddle
Actual site
Вы хотите, чтобы вы нажали кнопку «назад», чтобы принудительно перезагрузить страницу с помощью строки запроса в URL-адресе? – Sergio
Да, или просто обычный переход к URL-адресу в истории. Код 'document.ready' будет исправлять страницу. – Jonathan