$(window) bind hashchange how to check part hash changed?

前端 未结 2 807
野的像风
野的像风 2021-01-05 15:19

I am studing Google Ajax Crawlable

I use $(window) bind hashchange to control ajax page loading.

my url like: domain.com/#!/

2条回答
  •  天涯浪人
    2021-01-05 15:53

    I would store the original hash in a variable, and then examine the new hash to judge the change. Once that is done, set the new hash to be the original:

    var originalHash = window.location.hash;
    $(window).bind('hashchange', function() {
        var newHash = window.location.hash;
        //do your stuff based on the comparison of newHash to originalHash
    
        originalHash = newHash;
    });
    

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题