Jump to content

Problems with root-relative menus and <base href="">

Recommended Posts

Posted

The site I built uses 7.1  and works great. But a third party service needs to grab a "template" page to recreate the look of the site on their system.  I created a blank page and it works great with one exception. The root-relative (aka domain relative, or domain absolute) links in the menu are changing to be relative to the third party domain when delivered from their server.

So the link "/contact-us" doesn't point to "https://www.mysite.com/contact-us" but to "https://www.thirdpartyservice.com/contact-us" which is obviously a broken link.

There are two possible solutions as I see it:
1) Rewrite the entire navigation using absolute links instead of pages so that all links point to the correct site.
2) Find a way to edit the <base> tag which Squarespace adds very high up inside the <head> code:
 

<base href="">

Adding a new <base href="https://www.mysite.com"> line the head doesn't work. Apparently it isn't like CSS and is first-come first served.

Modifying or injecting a new <base> tag with JavaScript doesn't work either as apparently the DOM is rendered on the first pass and changes to this sort of thing aren't processed.

It would be a good Squarespace feature to be able to specify absolute vs root-relative menu links, or be able to modify the <base> tag somewhere in the settings. Does anyone know if this is possible?

Any other ideas? 

Thanks!
- Dan

  • Replies 1
  • Views 877
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Posted

Just in case anyone runs across this problem in the future, I was able to come up with a solution.

Injecting this script into the head rewrites the <base /> tag. 

<script>
      (function() {
      // Fetch base element and href attribute
      var baseElement = document.getElementsByTagName('base')[0];
      // Update base with domain to make it absolute 
      baseElement.setAttribute("href", "https://www.google.com");
    }());
</script>

Replace google.com with your domain (obviously).

The third party service is called IDXBroker and has a lot of realtor services. BTW, they even have a Squarespace support page and say that you must relink the entire menu. 

Personally, I love solving problems that others claim are impossible. 🙂  

Create an account or sign in to comment

You need to be a member in order to leave a comment


×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.