Best custom javascript to remove # from URL

One of our sites is a one page site so menu items are anchored to specific sections on the homepage. This means that a # appears in the URL. Is it possible to remove this?

I have been told it is possible with Javascript, but I’m not sure how to implement this and don’t want it to break the anchored links in the menu.

Yes, it should be possible with custom code.

@samliew thanks. Do you know how to remove it?

@waldo Do you know how to remove the # from a URL?

Hi there @emma1, here is a solution from Stackoverflow that may work: https://stackoverflow.com/questions/23312006/remove-hashtag-from-url

You will need to take the example code and put the following in the Before Body area of custom code:

<script>
$(window).on('hashchange', function(e){
    history.replaceState ("", document.title, e.originalEvent.oldURL);
});
</script>

Here is how to use custom code: http://help.webflow.com/faq/how-to-add-custom-head-and-body-code-to-a-webflow-site

After adding the code, republish the site.

I hope this helps!

Hello guys I am new to the community, is there any chance that webflow give clean URLs as a native option in a future update? I like building one page wonder sites and having the /# is a small problem.

Many thanks and stay safe out there!

1 Like