External URL to Anchor Or Wix Code Workaround?

Hi guys,

I really need a way to be able to directly navigate into an anchor from external source. I understand currently there is no standard method to do this as anchors do not have addresses of their own uniquely on the pages they are located (or do they now and have I missed something?).

I want to know if there is a way I can still accomplish that say with some kind of workaround that said if the referrer page was this url, then navigate to that anchor or some other similar funky workaround that would help me link one of my jotforms to a wix page but have it navigate to a particular anchor on that page where the relevant info presides. Maybe there is a way I can incorporate some URL parameters to trigger a scrollto function somehow. Please help! I am still a noob in trying to figure this out on me own easily without wasting a tone of time on it and am short on that denomination very badly. Just trying to see if it is even worth that waste of time lol.

Oh and the form is entirely too complex for Wix capability or rather for my capability with Wix code lol, so i have to use jotform for now and an running late and behind too.

Thanks

4 Likes

Hi Omid!

As ā€˜noob’ as you claim to be, you did got it right (mostly)!
You can totally navigate to an anchor using Query Params and here’s the API for it.
You simply need to include the anchor in the url as described in the link.

As for doing it from ā€œexternal sourceā€ I’m not sure I got you right but if you care to elaborate I’d be happy to try and help you further.

Doron. :slight_smile:

Danke! I will look into it and let you know if I had any further issues.

Did you ever figure out a workaround? Would love to do the same sort of thing. I’m surprised this still is not a feature.

I voted for WIX to give embedded anchors on sites your create their own URL, but in the meantime, I am wondering about a workaround.

I will send out and email newsletter and would like to have the ā€œRead moreā€ button land people on the page on our WIX site with the newsletter, ideally on the article they would like to read in full. (Even nicer would be to have activated the lightbox with the full text showing.)

If there is a WIX code workaround, please write out an example. I am not a programmer, but I can follow if things are made clear.

Thanks.

Did you ever figure out a workaround? Would love to do the same sort of thing. Thank you!

Hello, friends!

Just in case this topic is still relevant (because it indeed IS for me). I’ve found a workaround that was sufficient enough.

1) You’ll need WixCode so switch it on.

2) For some weird reason adding a hashtag to the end of your URL (i.e.: https://mySite.com#myAnchor) will mess with Wix router (I can’t be bothered figuring out this ridiculous behaviour) so just don’t use hashtags on your Wix site I guess. Also, adding a hashtag to my website link makes my main menu disappear… By the way, you can STILL access the hashtag, even though it gets ā€œeatenā€ by the router I assume:

wixLocation.hash; //returns URL hash string (with "#" character)
  1. Add some reasonable ā€œqueryā€ parameters to your URL (i.e.: https://mySite.com?a=services), the value of ā€œaā€ parameter will indicate an anchor on your page (you may replace ā€œaā€ with any variable name that is URI-valid). Now you can access query parameters via:
wixLocation.query; //returns array of query parameters
  1. Here comes another ā€œpleasant surpriseā€ from Wix. For some incomprehensible reason the following code:
$w("#myAnchorId").scrollTo().then(() => {
    console.log("Done with scroll");
});

doesn’t scroll me anywhere. No matter if I use my Anchor ID or any ID of any visible element on the page - the promise (returned by ā€œscrollToā€) gets resolved, but no scroll happens whatsoever. So this approach failed for me also. Throw it into a rubbish bin.

  1. WixCode is ā€œso liberatingā€ that I can’t even get the positioning of a page element! So in the end I became ā€œa bit upsetā€ and brute-forced it via:
let isMobile = (wixWindow.formFactor === "Mobile"); //this helps us determine if we're in mobile version

wixWindow.scrollTo(0, (isMobile ? 400 : 600)); //the second parameter being the Y coordinate (in pixels) of the page, also since the page height is different we need two values; in this case it's 400 for mobile and 600 for web

which is just plain stupid and quite an inflexible approach, but I honestly couldn’t do better. I tried…

  1. So, at the end of the day, the more I use Wix, the more my first ā€œwowā€-impression fades away. I’ve got at least 3 MAJOR complaints which really force me to consider solutions other than Wix. Maybe that’s the business model: ā€œGet subscriptions money for a year, a chunk of users will submit and conform anyways, then we’ll get a bunch of new ganders that will swallow the shiny bait. Repeat the cycle. Profitā€. Here’s my result code anyways:
import wixWindow from 'wix-window';
import wixLocation from 'wix-location';

$w.onReady(function(){ //this function runs after the page is loaded and is SLOW. Any reasonable Wix Page is SLOW AS HELL because there is A TON of unnecessary JavaScript code! Sorry... went on a rant again
    let query = wixLocation.query;
    let isMobile = (wixWindow.formFactor === "Mobile");

    if (query.hasOwnProperty("a")) { //this line checks the presence of "a" query parameter, you may need to use some other name
        switch (query.a) { //this accesses the query parameter "a", change the name according to your needs
            case "services": //you go here if your URL is "https://mySite.com?a=services"
                wixWindow.scrollTo(0, (isMobile ? 400 : 600)); //you can get the Y value by left-clicking on an anchor you have on your page and look at the "Position Y" parameter on the "editor panel" on the right
                break;
            case "about": //other cases are similar, this is for "https://mySite.com?a=about"
                wixWindow.scrollTo(0, (isMobile ? 800 : 1200));
                break;
            default:
                //do nothing
        }
    }
});

Hope this helps any of you, friends! Best regards

I’m shocked this is so complicated (impossible?). This should be simple. And it’s not. Dumb.

1 Like

Lack of the ability to externally link to Wix Anchors (like one can do with HTML on virtually any site!) makes the Wix Anchor system complete useless. Why bother with them, really? You can create an anchor menu on a page with them (which, after trying out, turned out to be a waste of time––so limited!)

I’m also shocked that Wix makes it so complicated and hasn’t noticed their failure with anchors.

1 Like

This works well for me and is a decent workaround although I also do not like to bruteforce it.

What I also found is that when I click on other links after using the query parameters in the URL, Wix continues to include the query parameters for all my site links. This is annoying if the users ever pay attention. Also I am doing this on my home page and when the home page is clicked, it always has the query string attached and skips the top of the page and always takes the user to the scroll location. Is there a way to strip the ā€œ?a=aboutā€ from the other links when they are navigated on the site.

@galija apologies for not replying earlier!

Alas, I was unable to find a solution for this. My site behaves the same way which I didn’t notice before you mentioned this in your comment. This behaviour appears to be ā€œnormalā€ for a Wix site… No more ranting from me :stuck_out_tongue:

Here’s another thread on the issue: https://www.wix.com/code/home/forum/community-discussion/clear-the-query-parameters-using-code

I have tried to ā€œcheat itā€ by adding:

wixLocation.query = '';

but it results as

TypeError: setting getter-only property "query" 

inside the browser console.

Here’s the official documentation: wix-location-frontend - Velo API Reference - Wix.com - no sign of ā€œsettersā€, only ā€œgettersā€. So, I assume you can’t modify or clear these parameters.

Better luck for us next time.

Super helpful - except that the pixel height of the page is different in Mobile - I’ll need to add a bit of logic to scroll to a different section if the view is on mobile

@tyler32398 Oh man, completely forgot to add that! Corrected my answer, and many thanks for the point!

Cheers

I came to know this issue when I tried to add a link in a description in Wix Events. That link is to the same site in Wix. Without this feature, I am afraid that the web designer looks so stupid to the visitor.

I guess that it is relatively easier to add this anchor function in Wix Events so I ask to do this effort first.

This is a simple and basic function in HTML. The fact that Wix lacks this feature suggests that Wix depends too much on client-side codes, which is, of course, consistent with another apparent fact that Wix is too slow.

I wonder if a system as Wix can have other implantation such as generating static HTML documents as much as possible and/or performing most functions in server-side codes.

Can’t believe that over a year after the first post in this thread that something so basic as being able to reference an anchor within a URL is still not supported in Wix. Come on guys.

Not sure if anyone still needs this, but you can just link to the section container ā€œidā€. Right click page, click Inspect, ctrl-f to find section, grab ā€œidā€ from section and paste it to the end of your URL like this:

This worked great for me. Thanks!!

This is a feature I really really want. WIX, please.

I’m new to Wix. Creating my first Wix website. I don’t have coding skills. And like many in this thread, I’m really disappointed that Wix would neglect such a basic function as enabling linking to an anchor from an external site. I need this feature as part of my social strategy, to allow me to deep link into my site from social media. For any Wix moderator monitoring this site, please prioritize this request.