How to hide the name of a section inside URL?


Topic: How to hide the name of a section inside URL?

pawled pro premium asked 1 months ago

How to hide this part (#)?

https://example.com/#this_part


Tomek Makowski staff commented 1 months ago

hi

Unfortunately link doesn't work

Regards


pawled pro premium commented 1 months ago

It's just example. What I mean.

I want to hide last part of address. The name of section (one page website after scrolling).


Tomek Makowski staff commented 1 months ago

You can always use link shortener like

https://app.bitly.com/


pawled pro premium commented 1 months ago

You don't understand. I'm talking about one page website navigation. When I click scrolling link, it adds section name at the end of address. I want to hide this part (#this_part). Address should always looks like https://example.com/


Tomek Makowski staff answered 4 weeks ago

Try out this solution

window.addEventListener('hashchange', () => {
   history.pushState("", document.title, window.location.pathname);
});

Regards


pawled pro premium commented 3 weeks ago

Unfortunately it doesn't work.


Tomek Makowski staff answered 3 weeks ago

hmm strange, could you show your code in the snippet code editor

https://mdbootstrap.com/snippets/

My code looks like this. Be sure that you have your js code in proper position. Moreover it only works when you click in the link which have a href attribute with hashtag sign

<body>
<a href="#first">first</a>
<div style="height: 120vh"></div>
<section id="first" style="height: 30vh">dddd</section>

<!-- jQuery -->
<script type="text/javascript" src="js/jquery.min.js"></script>
<!-- Bootstrap tooltips -->
<script type="text/javascript" src="js/popper.min.js"></script>
<!-- Bootstrap core JavaScript -->
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<!-- MDB core JavaScript -->
<script type="text/javascript" src="js/mdb.min.js"></script>
<!-- Your custom scripts (optional) -->

<script>
  window.addEventListener('hashchange', () => {
    history.pushState("", document.title, window.location.pathname);
  })
</script>
</body>

Regards


Please insert min. 20 characters.
Status

Answered

Specification of the issue
  • User: Pro
  • Premium support: No
  • Technology: Other
  • MDB Version: -
  • Device: Any
  • Browser: Any
  • OS: Any
  • Provided sample code: No
  • Provided link: Yes