Is there a way to show a lightbox on a specific dynamic page instead of every dynamic pages?
In my case, I’m working on a website dedicated to movies (from a database; 1 movie = 1 dynamic page) and I’d like to add some warnings on a lightbox for specific movies, something like this :
“This movie contains strobe effects and strong language. Pursue or come back to every movies?”
I don’t want the lightbox to show on the first page visited either, only the specific pages I chose.
Hi there I do something similar on my site. There are a couple of ways to accomplish this.
Option 1 (Best for 1 page)
If you’re only doing this for 1 dynamic page, this way works well.
Since each dynamic page has a unique url, you can find some text in the url for the specific page and target only that page.
For example, the code below looks for my dynamic page url that contains the word “technology” and opens the Lightbox.
import wixLocation from 'wix-location';
import wixWindow from 'wix-window';
$w.onReady(function () {
if (wixLocation.url.includes("Technology")) { // Your url word
wixWindow.openLightbox("User Sign In"); // Your Lightbox name
}
});
Option 2 (Best for many pages)
Create a column in your database, field type boolean. Check the row items where you want the Lightbox to appear, as in the image below.
The code below checks the “warning” column in my database, and if the value is true (if the field is checked) then the Lightbox will open.
import wixWindow from 'wix-window';
$w.onReady(function () {
$w("#yourDataset").onReady(() => {
var currentItem = $w("#yourDataset").getCurrentItem();
if (currentItem.warning === true) { // Your Field Key
wixWindow.openLightbox("User Sign In"); // Your Lightbox name
}
});
});