0

I want to remove # from the Url when clicking for example at <a href="#contact" style="padding-bottom: 33px; padding-top: 5px;">Contact</a>.

By default I get example.com/#contact but I want to get just example.com without the # in the url when clicking on the link.

A-Sharabiani
  • 13,270
  • 12
  • 87
  • 109
Dexo
  • 23
  • 1
  • 5

2 Answers2

0

You could do it via jquery?

something like this?

$("a#linkTo").click(function() {
    $('html, body').animate({
        scrollTop: $("#elementtoScrollToID").offset().top
    }, 2000);
});

Another option would be to add a custom class to each section you link to, then use jquery/js to scroll to that.

As far as I know its better to keep the # in the url for SEO?

sample from : jQuery scroll to element

Community
  • 1
  • 1
CapeCoder
  • 531
  • 6
  • 11
  • Thanks for the help but unfortunately it didn't worked for me and I don't know if it's better for SEO. I just wanted to have when clicking on the link it scrolls to the anchor point without changing the url like they did on this site https://css-tricks.com/examples/SmoothPageScroll/ – Dexo Jun 10 '16 at 21:06
0
<script>
 function clsl(){
    var c = document.getElementById("aaa").href;
    var d = c.replace(/[#]/gi, '/')
    window.location.href=d;
 }
</script>

Link:

<a href="#contact" id="aaa" style="padding-bottom: 33px; padding-top: 5px;" onClick="clsl()">Contact</a>

First get link and then replace hash # with / using replace function and then redirect.

Hamza Zafeer
  • 2,052
  • 12
  • 27
  • 34
  • thanks for the anwser but now I get an url like "example.com/contact" instead of just example.com I don't want the url to update when using the scroll to #anchor-id. For example like on this page: https://css-tricks.com/examples/SmoothPageScroll/ – Dexo Jun 10 '16 at 15:41