2

I am used to using href="#" during development as placeholder links so that if you accidentally click on it, nothing happens and it will not jump the page around while testing the page i.e. you know exactly which is a placeholder and which is a broken link.

However, When baseurl is defined in the head, href="#" fetches the baseurl address instead of the current page and appends the # at the end. This causes placeholder links to load the index page always. Annoying.

<!doctype html>
<html>
<head>
<base href="http://localhost">
</head>
<body>
<p><a href="#">placeholder # only</a></p>
<p><a href="">empty string</a></p>
</body>
</html>

Is there a way to get back the "placeholder" behavior other than specifying the full path in the <a>'s href?

Jake
  • 11,273
  • 21
  • 90
  • 147

4 Answers4

1
href="javascript:void(0);"

try this, so onclick the page wont jump nor will it be refreshed

Sweetz
  • 344
  • 1
  • 4
  • 17
0

This might be more of a hack than anything but you could always just ignore clicks from anchor tags:

$('body').on('click', 'a[href="#"]', function(e) { e.preventDefault(); });
Wex
  • 15,539
  • 10
  • 64
  • 107
0

If you are currently in development I suggest removing your base tag. It defines the behavior of all the anchor tags on that page. For more information : http://www.w3schools.com/tags/tag_base.asp

Cristi Marian
  • 443
  • 8
  • 18
0

do it with javascript:

function onClick(event) {
  document.getElementById('id').scrollIntoView({
    behavior: 'smooth'
  });
}

https://stackoverflow.com/a/48901013/4185912

Sergey Gurin
  • 1,537
  • 15
  • 14