I would like tGenerate a unique anchor URL to share across platforms, so when visitors click the link, they’re brought directly to the anchor on the web page, so they don’t need to scroll to find information especially that I am going to use that for the documentation webpage
I found the below article explaining how to do that in Wix Editor
And then the url structure will look like domain.com/#elementID
Element ID is the id of the element set in the code properties panel, not the name you set within the editor
Super helpfull! Thank you! Only question I have is can we change the code somehow to instantly open the section without 1 second delay and smooth scroll?
This is awesome, thanks for sharing the info. I’m not sure if this helps anyone, but I felt uncomfortable with user/visitors being able to access any hashtags based on naming.
This is how I’m avoiding it. There might be a better way but this seems to work for me
const allowedAnchors = ["allowedID", "anotherAllowedID"]; // Add more as needed
// Get the anchor from the URL
const anchor = wixLocation.url.split('#')[1];
// Check if the anchor is in the allowed list
if (allowedAnchors.includes(anchor)) {
// Scroll to the specific anchor if it's one of the allowed strings
$w('#' + anchor).scrollTo();
}
@noahlovell Great tip, this worked perfectly except for one thing… I have 2 versions of the section that I want the anchor URL for… one layer for desktop and an alternate layer (different layout) for tablet/mobile. The anchor URL works for the desktop version of the section but not for the tablet/mobile version of the section because the section #ID needs to be unique. Is there any workaround for this scenario? Otherwise, the anchor URL won’t work if someone is on a tablet or mobile or similar breakpoint. Thanks!
Hi Noah, thanks for the tip with the code. It works well as long as I just add it once. I have several items on one page I want to link with an anchor-url but somehow it doesn’t work for more thank one # on one page. Do you know what the problem might be?
Many thanks, Nadine
This isn’t working for me, and I’m not sure why. It’s parsing correctly. Console log shows the right anchor var. It’s the scrollTo() that isn’t working at all. I can’t even scrollTo() an object id. This is a free site I’m building on, is scrollTo() only functional on paid sites??