jQuery .load:刷新页面时加载同一页面的任何方法


jQuery .load: any way to load the same page when page is refreshed

所以我有一个将页面加载到容器div的网站:

function goto(addr) {
    $("#content").load(addr);
}

以及执行它的链接

<a href="#" id="aboutus" onclick="goto('page/aboutus.php');">About us</a>

我的问题是,每当刷新页面时,加载的内容都会重置为默认页面(页面/主页.php)。我该怎么做才能加载上一个显示的页面?

例如,使用本地存储或会话。本地存储示例:

$(document).ready(function() {
    var lastPage = localStorage['lastPage'];
    if (!lastPage) { // If user was on any url before we will exectue goto function
        goto(lastPage)
    }
    function goto(addr) {
         localStorage['lastPage'] = addr; // Set url to local storage before load page
         $("#content").load(addr);
    }
});

不仅是本地商店,而且您需要更改url的哈希值,然后在执行一个函数来捕获哈希代码并在您的"goto"函数中执行...

"类似的东西"

function hashnav(){
   var hashfull = document.location.hash
   var hash = hashfull.replace('#', '');
   var $page = '';
   goto(hash);
}
function changeHash($hash) {
   window.location.hash = $hash;
}
function goto(addr) {
   changeHash(addr);
}
$(window).bind( 'hashchange', function() {
   hashnav();
   return false;
});