I want to link text to a URL for a lightbox, so that the lightbox pops up when the text is clicked. This seems like it should be simple! I followed these instructions, and it still isn’t working for me. I am linking to text in a dataset that flows into a dynamic page. The text will not link to anything, and even when I try to put in the lightbox URL directly it gives me a 404 not found error page.
My code is in the screenshot below. The line 'import wixLocation from ‘wix-location’; isn’t visible because it’s further up the code, but its in there.
@anhelinak The code’s express purpose is to provide that missing functionality and it definitely does work.
@Sara
That’s not what the lightbox URL should be. A query string should be appended to the end of the page name/path. You include an extra slash which changes the meaning. It’s the page that isn’t found, not the lightbox.
I’m a bit confused by why you’ve copied this code example if you only want to open the lightbox on a button click. You’d be better off declaring a click handler on the button and calling only wixWindow.openLightbox(). Or is it because you want the URL to change so people can copy and paste /share it?
@Lee, thank you for looking into this with me. Here is some more information:
The text I want to link to the lightbox pop-up is in this page here: https://www.teratec.us/FiberOpticTestEquipment/FTE-7100-MICROTDR . You can see the last bullet says ‘View the detailed Help Screen.’ It currently does not link to anything. This is a dynamic page, and all of the text is contained in a dataset. The bulleted text is in rich text format and should be linkable within the dataset cell.
The lightbox is called ‘7100 Help Screen.’ Here is a screenshot.
As you can see, I’m not using a button to open this lightbox- only dynamic text. I don’t really need the URL to be shareable, I’m only concerned that the selected text opens this lightbox.
Thank you for your input! I look forward to your feedback.
It says “Wix code SDK error: The name parameter that is passed to the openLightbox method cannot be set to the value . It must be of type string.
FiberOpticTestEquipment (Title)
Line 112”
The error you’ve screenshotted is because the code always passes the query string (even if there isn’t one) to wixWindow.openLightbox(). You’d ordinarily want to check if it was empty first.
From my limited testing it looks like if you try to navigate to the same page but with an added query string the navigation isn’t detected / no lightbox is shown. So I’d go with my initial recommendation and use a click handler.
$w.onReady(() => {
$w(‘#textOrButton’).onClick(() => wixWindow.openLightbox(‘7100 Help Screen’));
});
To make this dynamic you can parse out the model number from the path or since you’ll be naming all the lightboxes manually anyway just give them the same name.
$w(‘#textOrButton’).onClick(() => wixWindow.openLightbox(wixLocation.path[1] + ’ Help Screen’));
Here you’d name the lightbox “FTE-7100-MICROTDR Help Screen”.