简体   繁体   中英

colorbox callback confusion

I call the colorbox twice. First call is on click. When colorbox is open, you can print its content on click:

$("a.nivoImageLink").colorbox({
    opacity:.8,
    onComplete:function() {
        cboxPrint(false);
    }
});

And second: colorbox opens on the thumbnails print-icon click, the print window open, after print procedure the colorbox closes again:

$("a.print").click(function() {
    $("a.nivoImageLink:not(:hidden)").colorbox({
        open:true,
        onComplete:function() {
            cboxPrint(true);
        }
    });
});

This works so far. But when I open the colorbox on the print-icon (second call), the colorbox opens just in that case, regardless of which call I do. This is the callback function:

function cboxPrint(autoprint) {
    if (autoprint) {
        setTimeout(function() {
            window.print(); 
            $.colorbox.close();
        },800);
    } else {
        $("a.cboxPrint").click(function() { 
            window.print(); 
        });
    }
};

can someone please help me out?

I'm not quite sure I understood your question, it is still too early in the morning ^^. Have you considered how colorbox works? Once colorbox has been opened, it creates some markup and then just hides that from view, and unhides it when you want to show it again. If I remember correctly. You may need to clear the colorbox code if you are getting weird results from multiple colorboxes on the page.

You could use:

$.colorbox.remove()

This would truly clear all traces of colorbox code from your document. There are more elegant ways of dealing with this problem like using the onClosed callback function.

Although, as I said before, I didn't quite understand your problem so this may be of little interest to you. Good luck all the same :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM