I was testing the Photo Gallery extension as a way to spice up some of our categories. For example showing pictures of our paint products in action. You can see a simple implementation here: https://www.allfrom1supply.com/all-departments/paint-store/all-products-paint-coatings/chem-bake-1-step-1201
By default the images open in a new tab -unchecking the 'show in new tab' option just generates a 404 page. I wanted to create a simple lightbox effect. I created a basic html test page on my desktop, with code copied from two of the images on the page I referenced, and tried multiple variations of script like that below and it works on my desktop.
<script>
document.addEventListener("DOMContentLoaded", function() {
let gallery = document.getElementById("cct_netsuite_photogallerycct");
if (!gallery) return; // Exit if the container is not found
gallery.querySelectorAll("a[href$='.jpg']").forEach(link => {
link.addEventListener("click", function(event) {
event.preventDefault(); // Prevent default new tab opening
openLightbox(this.href);
});
});
});
function openLightbox(imageSrc) {
let lightbox = document.createElement("div");
lightbox.id = "lightbox";
lightbox.style.cssText = position: fixed; top: 0; left: 0; width: 100%; height: 100%;
background: rgba(0,0,0,0.8); display: flex; align-items: center;
justify-content: center; z-index: 9999;
;
let img = document.createElement("img");
img.src = imageSrc;
img.style.cssText = "max-width: 90%; max-height: 90%; border: 5px solid white;";
lightbox.appendChild(img);
document.body.appendChild(lightbox);
// Close the lightbox when clicking anywhere on the overlay
lightbox.addEventListener("click", function() {
lightbox.remove();
});
}
</script>
But adding this code using the SMT editor in a CMS HTML component at the bottom of the category does not work. All continue to open in a new tab. Is this code blocked by design, or might there be some simple way to do this someone can suggest? I lack advanced skills and was just looking for a lightweight simple solution. I tried CSS only solutions first to avoid the scripting, and also -since it looks like it might use bxSlider based on the class names- tried to use parameter information from that site to try to force the links to open in a lightbox, modal window or popup but no luck.