Streaming live at 10am (PST)

Best custom javascript to remove # from URL


#1

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.


#2

Yes, it should be possible with custom code.


#3

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


#4

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


#5

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!