jackmoore / colorbox

A light-weight, customizable lightbox plugin for jQuery
http://www.jacklmoore.com/colorbox/
MIT License
4.75k stars 1.14k forks source link

question - how to get title or filename of image in popup #893

Closed ash73 closed 3 years ago

ash73 commented 3 years ago

Hi, noob question, not an issue... is it possible to get the title or filename of the image displayed in the colorbox popup, after the cbox_complete event? I want to log which images are viewed.

By popup I mean the full size picture displayed with left/right arrows when the user clicks on a thumbail.

$(document).bind('cbox_complete', function(){ var picture_title = document.getElementById(???).?????; var picture_filename = ???; });

jackmoore commented 3 years ago

You got it. Colorbox elements have predictable selectors. How about this:

$(document).bind('cbox_complete', function(){
    var title = document.getElementById('cboxTitle');
    var filename = document.querySelector('.cboxPhoto');
    if (title && filename) {
        console.log(title.innerText, filename.src.split('/').pop());
    }
});
ash73 commented 3 years ago

That's perfect! Works just fine, many thanks for the quick reply.