0

I have a base URL which placed in my header for all the pages. But I have a page which must be link to just '#' for smooth scrolling to an anchor. But the URL concatenates the base URL. Instead of just the '#' for the href attribute, it shows http://localhost/Sample/#

Here is the code for the base:

header.php

<base href="<?php echo URL ?>">
ajdeguzman
  • 1,203
  • 3
  • 15
  • 25

1 Answers1

1

When using the base element, all relative URLs in the document are resolved according the the href value of the base element previous defined. This means elements with relative links, including anchors are resolved to such base element href value. If you do not want to have that side effect, you might want to look at the HTML5 History API, which will allow you to have a much more control and desirable outcome if you need to use the base element.

If you want to do something more of a hack, you can wait for the page to load all assets, then set all assets paths to be the full url, and then change the base element href value to be '#' so you get the outcome you are looking for, but again, this is nasty and not recommended.

joseeight
  • 894
  • 7
  • 10