浏览器后退按钮未更新页面 [英] browser back button is not updating page

查看:73
本文介绍了浏览器后退按钮未更新页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jquery click事件在井号之后设置URL. URL设置正确,但是当我使用浏览器的后退按钮时,它并没有带我到上一页.

I'm setting the URL after the hashmark with a jquery click event. The URL is getting set properly but when I use the browsers back button it doesn't take me to the previous page.

在点击事件之前,URL如下所示:

Before my click event the URL looks like this:

http://example.com/menu.php?home

我的点击事件如下:

$('#visits').click(function() { 
    $('#main').load("visits.php?type=1&view=1", function () { 
        location.href = "#visits";  
    });
    return false;
});

我的网址现在看起来像这样:

My URL now looks like this:

http://example.com/menu.php?home#visits

似乎没有通过浏览器的后退按钮调用menu.php.

It seems as though menu.php doesn't get called with the browsers back button.

知道我缺少什么吗?

推荐答案

您可以编写如下代码:


var _hash = '';

function myHashChangeCallback(hash) {
    // handle hash change
    // load some page using ajax, etc
}

function hashCheck() {
    var hash = window.location.hash;
    if (hash != _hash) {
        _hash = hash;
        myHashChangeCallback(hash);
    }
}

setInterval(hashCheck, 100);

这篇关于浏览器后退按钮未更新页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆