The goal is to be able to click a button on a WIX-page with a URL.
The Site looks like this for example:
Button1 shows container1 and Button2 toggles to container2
The code for this would be:
$w.onReady(function() {
const buttons2 = [$w('#b1'), $w('#b2')];
const boxes2 = [$w('#G1'), $w('#G1e')];
buttons2.forEach((button, index) => {
button.onClick(() => {
showBox(index, boxes2);
});
});
});
function showBox(index, boxes) {
boxes.forEach((box, boxIndex) => {
if (boxIndex === index) {
box.expand();
} else {
box.collapse();
}
});
}
Now this should be achieved by adding to the same URL a trigger:
I tried it this way:
function getUrlParameter(name) {
const results = new RegExp('[?&]' + name + '=([^&#]*)').exec(wixLocation.url);
return results === null ? null : decodeURIComponent(results[1].replace(/+/g, ' '));
}
$w.onReady(function() {
if (getUrlParameter('trigger') === 'click') {
$w('#b2').click();
}
});
…but it did not work because in WIX the property ‘click’ does not exist on type ‘Button’.
Does someone know how to achieve this or is this even doable on WIX.com?