1
$('#ajax-links a').live('click', function(e) {
    var url = $(this).attr('href');
    url = url.replace(/^.*#/, '');
    $.history.load(url);
    return false;
});

Whenever I replace 'click' with 'dblclick' it still behaves as the click event. The demo is here (http://www.serpere.info/jquery-history-plugin/samples/ajax/) and the source can be download from here : https://github.com/tkyk/jquery-history-plugin/tree/master/samples/

user784637
  • 15,392
  • 32
  • 93
  • 156

1 Answers1

2

Try prevent default on single click when adding dblclick:

Instead of return false; you can prevent the default action for the event:

If you don't want the event to bubble throw the DOM you can use the event.stopPropagation() function

$('#ajax-links a').live('click', function(event) {
    event.preventDefault();
});
$('#ajax-links a').live('dblclick', function(event) {
    event.preventDefault();
    var url = $(this).attr('href');
    url = url.replace(/^.*#/, '');
    $.history.load(url);
});

Dblclick events only gets fired at dblclick: see: jsfiddle.net/cR5ZS

The reason you think its get fired on single click can be that your link refers to something like: #/some_page/ and your dblclick event handler does almost the same. Saves /some_page/ with $.history plugin and in my experience the $.history plugin does almost the same: takes the url parsed to with the call and puts it in the hash : url=/some_page/ becomes #/some_page/

Andreas

Andreas Louv
  • 46,145
  • 13
  • 104
  • 123
  • That's a great work around. I think double clicks default to single clicks for some reason, would you happen to know why? Perhaps because anchors default to single clicks? – user784637 Aug 11 '11 at 10:47
  • 1
    Im sorry not writing this before. Dlbclick event is fires when to clicks appears quickly. When clicking once the single click event fires. Im pretty sure your single click does almost the same as that dblclick you are writing. Sorry for sounding confusing. – Andreas Louv Aug 11 '11 at 10:59
  • Hi Andreas, Thanks so much. I was referring to the original code when I said that the double clicks were defaulting to single clicks when I changed the 'click' event to 'dblclick' – user784637 Aug 11 '11 at 11:06
  • 1
    I dont think its that way: http://jsfiddle.net/cR5ZS/ The reason you think so can be that your link refers to something like: `#/some_page/` and your `dblclick` event handler does almost the same. Saves `/some_page/` with `$.history` plugin and in my experience the `$.history` plugin does almost the same: takes the url parsed to with the call and puts it in the hash : `url=/some_page/` becomes `#/some_page/`. – Andreas Louv Aug 11 '11 at 11:10
  • My link DOES refer to #something. Thanks for the explanation and in depth exploration of this problem. – user784637 Aug 11 '11 at 11:15
  • @AndreasAL let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/2357/discussion-between-ledzeppelin-and-andreas-al) – user784637 Aug 11 '11 at 11:21