Hello everybody ,
On this forum, someone gave me a usefull piece of code, that i use to set a container box as a link …
import wixLocation from ‘wix-location’ ;
$w . onReady ( function () {
$w ( “#box140” ). onClick ( ( event ) => {
wixLocation . to ( “/my-page” );
})
});
It work well, but to be more accurate, i would like to link to an anchor on this page.
Of course i tryed /my-page#anchorname, but it doesn’t work. I checked this wix site already but it don’t help me since my coding skills are to low.
Can someone help me please ?
(I’m not english native speaker)
Hi, This one is a tricky alternative. Please use this:
//Add query parameters while redirecting.
wixLocation.to("/my-page/?keyName=containerName")
//Then on the other page
importwixLocationfrom'wix-location';
$w.onReady(()=>{
let query = wixLocation.query; //This will get the container name from URL
$w(`#${query.keyName}`).scrollTo(); //This will scroll to the container.
})
Oh it’s working now ! Don’t know i you readed the previous answeer but i deleted it.
It’s working perfectly. The scroll effect is a bit slow but thats fine.
thank you so much.
One more question, base on this code for an other page
importwixLocationfrom'wix-location';
$w.onReady(function () { $w("#box140").onClick( (event) => { wixLocation.to("/my-page"); }) });
Do you think it’s possible to link an url AND open it on a new windows (new tab) ?
@wix-expert-velo-cert it’s all good i used an other way for this it’s okay.
Thanks again have a good day