colorbox loading same document multiple times in firefox
Hello I have a page that render's a large number of tokens comingfrom an AJAX request. This is the method that renders the contents:
function renderTextView(documentId, manuscriptId) {
$("#textView").empty();
$(".token-display a").die();
$.each(window.g_cacheAllTokens, function(idx, token) {
var html = renderToken(token, documentId, manuscriptId);
$("#textView").append( html );
});
$(".token-display a").live('click', function() {
var url = $(this).attr('href');
$.fn.colorbox({
opacity: 0.25,
href: url,
open: true,
onClosed: function() {
reloadViews(documentId, manuscriptId);
}
}); // colorbox
return false;
});
// enable tooltips for tokens
if( true == getEditorOption('showTooltips') ) {
$(".token-display").tooltip();
}
} // renderTextView
For every token rendered, I set a live handler that opens a colorbox on 'click'. In Chrome it seems to behave fine, but in Firefox. Once I open a colorbox and then close it,the second time I open it (the same one or any other token in the screen) it requests the de开发者_StackOverflowstination URL twice, if I do this three times, then it does performs the request three times and so on.
As you can see when the colorbox closes, I reload the view, so I get new tokens and refresh the handlers.
This is making my application unusable after little time using it, so it's a pretty bad issue.
I have no idea what it could be and I don't even know how to debug it.
I've also noticed that this happens if the page displaying inside the Colorbox also includes the JavaScript for Colorbox. That was my problem at least. Whatever page that you load in the Colorbox must not include duplicate JavaScript.
Hopefully this may help someone who was having similar problems as me.
In case someone encounters a similar problem, I managed to solve it by changing the click handler from being dynamic to being static, like so:
$(".token-display a").click(function() {
// ...handler code...
});
instead of what I had before:
$(".token-display a").live('click', function() {
// ...handler code...
});
Seems that Firefox was adding the handler twice for some reason.
精彩评论