且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在不触发hashchange事件的情况下更改哈希

更新时间:2021-07-12 17:20:30

你可以拥有类似的功能这个:

You can have a function like this:

function updateHash(newHash){
  ...
  oldHash = newHash
}

然后在你的setTimeOut中你需要做

then in your setTimeOut you need to do

function(){
  if(oldHash != currenHash){
    updateHash(currenHash);
  }
}

所以现在你可以手动调用update hash并赢了不会被事件触发。您还可以在updateHash中使用更多参数来执行其他操作。

So now you can call update hash manually and it won't be triggered by the event. You can also have more parameters in updateHash to do other things.

顺便问一下,你看过jquery历史插件了吗? http://tkyk.github.com/jquery-history-plugin/

By the way, have you looked at the jquery history plugin? http://tkyk.github.com/jquery-history-plugin/