开发者

jqprint print dialog appearing twice

开发者 https://www.devze.com 2023-04-05 17:32 出处:网络
I\'m working on a project where we\'re trying to use the jquery jqprint plugin to print out some content from our webpage. The user selects an item from a grid by double clicking on it, and is directe

I'm working on a project where we're trying to use the jquery jqprint plugin to print out some content from our webpage. The user selects an item from a grid by double clicking on it, and is directed to a details page which they can then print out by clicking on a link. Whe开发者_JS百科n they click on it though, it opens up two print dialog boxes, one after the other, and we only want one. Any ideas what's causing this?

The code:

$(document).ready(function () {
    $("#PrintLink").die();
    $("#PrintLink").live("click", function (e) {
        $("#ContentToPrint").jqprint({ importCSS: 'true' });
        e.preventDefault();
    });
    return false;
});

Also worth noting:

I haven't been able to find documentation for jqprint, so links to it would be greatly appreciated. Navigating away from the page and then back to it causes the print link to work properly. I'm pretty sure the preventDefault() and return false are redundant, but I didn't write the code and I'm not sure which to get rid of :P Thanks for any help


You can remove the return false, and the preventDefault should be placed before jqprint. Also, you should't need die() either, but then again...there are cases where it could be useful I just don't see it here.

I looked at the source for jqprint and if you're using the latest version I don't see any reason to be having 2 dialogs.

http://plugins.jquery.com/node/14098

UPDATE: You could also try using click() instead of live()...live() should work fine but then again, I've had bugs in jQuery before.


My boss figured it out; a similar printing jquery was getting left in the footer from a previous page, and referenced the same id as this, so that clicking the link caused both functions to run. Changing the ids fixed the problem. Thanks to Shawn for his efforts to help.

0

精彩评论

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