I am using an icon button, for more info. If possible, I will appreciate if you could give me an example code for me to follow as I am still not very experienced with programming yet.
I donât think this is possible.
But I would be gladly to help if you can give more detail on what exactly is the problem.
This isnt really a problem, I just wanted to explore what can be done with Velo Dev Mode. Thus, I am perfectly fine if this is not achievable as I am just trying to give my website some additional features.
make an array of links
cont links = ["/home","/page1","page2","page3"]
make a click functions to search it and go to a random number.
onClick(){
const min = 0;
const max = links.length-1;
const linkNr= Math.floor(Math.random() * (max - min)) + min;
wixLocation.to(links[linkNr])
}
Kind regards,
Kristof
Hi, thank you for giving me this code to follow, defintiely couldnt have done without your help! However, it seems like I am received a parsing error in the } of the last line.
Also, I have edited a bit of stuff here and there so I am not sure if the parsing error is due to my edits.
import wixLocation from âwix-locationâ
const links = [ â/homeâ , â/searchresultsâ ]
$w ( â#iconButton1â ). onClick ( ( event ) => {
const min = 0 ;
const max = links . length - 1 ;
const linkNr = Math . floor ( Math . random () * ( max - min )) + min ;
wixLocation . to ( links [ linkNr ])
}
Happy to help,
Like you say, the error is at the }
This probably means there is something to much or less.
in your case you didnât close all ( .
so instead of ending with }
it should end with
})
Solution code
importwixLocationfrom 'wix-location'
const links=["/home","/searchresults"]
$w("#iconButton1").onClick((event)=>{
constmin=0;
constmax=links.length-1;
constlinkNr= Math.floor(Math.random()*(max-min))+min;
wixLocation.to(links[linkNr])
})
@volkaertskristof
Yep, carelessness kills again. Thanks for your help once again!