Link to internal page and scroll to anchor

Hi,
I’m trying to scroll to an internal page “/” and scroll to anchor.
The reason I’m using Corvid is that I want to fire an event to GA.

The scrollTo function has one of two undesirable effects.

  1. if is I use $w(#myElement") i achieve:
  • error because the element is not present on the source page
  • scroll to an irrelevant element on the source page
  1. if I use coordinates to scroll the scrollTo() works prior to the WixLoaction.to()

Example:

export function pdpButton_click(event) {
wixLocation.to(“/”);
wixWindow.trackEvent(“CustomEvent”, {
“event” : “click”,
“eventCategory”: “pdp”,
“eventAction”: “myButton”,
“eventLabel” : “myEventLabel”.,
} );
wixWindow.scrollTo(100, 500);
}

https://support.wix.com/en/article/request-linking-to-an-anchor-from-an-external-source if this was possible the.to() was enough…

It probably takes more time to execute the wixLocation.to() method than the wixWindow.scrollTo(x, y) method, hence your side-effect #2. As for #1, make sure #myElement is a valid id of the element on the page you are going to .

From https://www.wix.com/corvid/reference/wix-location.html#to , I see there’s the possibility to use the link pattern /localPageURL# as long as the item “supports the scrollTo function”.

If your $w(" #myElement ") supports the scrollTo function, your code should probably look something like this if you decide to take up my suggestion:

export function pdpButton_click(event) {
wixLocation.to(“/#myElement”);
wixWindow.trackEvent(“CustomEvent”, {
“event” : “click”,
“eventCategory”: “pdp”,
“eventAction”: “myButton”,
“eventLabel” : “myEventLabel”
} );
}

Note that “/” takes you to your home page.

Good luck.

Hi,
Thanks for the detailed response!
i resolved using the :
" as long as the item “supports the scrollTo function”."

When I used an anchor it didn’t work, but with a text it did.
Strange I would think that anchors are the classic scrollTo() elements…

the little arrow on the top left is the source button:
https://www.mayarica.com/product-page/bull-necklace-guerrero

You’re welcome. I’ve had some issues with anchors as well. Wrapping the anchor.scrollTo() function in a setTimeout function usually undoes its strange behaviour, but you can’t do this with a simple wixLocation.to(). So, there are workarounds if you must use anchors, but I think you worked around it nicely yourself already.