views:

19

answers:

1

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 another good one please let us know).

+2  A: 

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.

Nick Craver
great... you are very familiar with javascript. A similar package that we were using had this issue: http://stackoverflow.com/questions/3162579/why-does-really-simple-history-javascript-library-fire-off-event-twice-in-ie-but do you know why?
動靜能量