开发者

jQuery's History (and Bookmark) plugin may have a bug?

开发者 https://www.devze.com 2023-01-05 17:35 出处:网络
I am suspecting in file http://github.com/tkyk/jquery-history-plugin/blob/master/samples/ajax/ajax.js line 13 and 14

I am suspecting in file http://github.com/tkyk/jquery-history-plugin/blob/master/samples/ajax/ajax.js

line 13 and 14

            load(url);
            $.history.load(url);

in Firefox, Chrome, and IE 8, I see that the page is loaded twice when 1, 2, or 3 is clicked on.

Is it true that line 13, "load(url);" can be removed because $.history.load(url) will trigger the function registered with $.history.init(), which does a load() already?

Can someone familiar with the package confirm this?

(This is the best Ajax History and Bookmark library I found for jQuery. If someone knows anoth开发者_Python百科er good one please let us know).


Yes, you can remove the load(url) call and it'll work, what happens is that the init takes a callback, if the location hash changes (which it checks every 100ms) it'll run that callback again.

This part:

$.history.init(function(url) {
  load(url == "" ? "1" : url);
});

That function gets run every 100ms, if the current location hash (or appState in the plugin) doesn't match what it was previously. The load() call in the actual click handler is in addition to this, so currently it's running instantly, and 0-100ms later again.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号