LightGallery how to get url of the currently displayed image?

34 Views Asked by At

I'm using lightGallery and I want to pass the url of the currently displayed image to PHP using fetch API to send HTTP request. Here the code of my js test script:

function sendPhotoData() {
   var data = {
      name: "Bob",
      email: "[email protected]",
      image_url: ????????,
   };
   // call the fetch function
   fetch("function.php", {
       method: "POST",
       body: JSON.stringify(data),
       headers: {
           "Content-Type": "application/json",
       },
   })
        // receive the response
       .then((response) => response.text())
       .then((data) => alert(data));
};

I read the lightGallery documentation but didn't understand how to get the url of the currently displayed image!

The same script works fine with PhotoSwipe when I set "image_url: pswp.currSlide.data.src", I'm looking for an equivalent for lightGallery.

Thanks for your help because I'm not a js guru...

0

There are 0 best solutions below