2

If someone access my website via this kind of url: "www.xxx.com/#somehash", I want the page top open as "www.xxx.com"

for that, I use this script on document ready:

location.hash="";

It almost works as it open the website as "www.xxx.com/#"

But I just can't get rid of the final "/#"

What can I do?

Thanks.

EDIT: I don't want to refresh the page or use any HTML5 exclusive script, just find a script that does the same as the one above but without the hash termination.

Baylock
  • 1,246
  • 4
  • 25
  • 49
  • duplicate: http://stackoverflow.com/questions/1397329/how-to-remove-the-hash-from-window-location-with-javascript-without-page-refresh – Jerzy Zawadzki Aug 01 '13 at 15:20
  • 1
    Have you considered a mod_rewrite solution if you are using Apache? – thatidiotguy Aug 01 '13 at 15:21
  • @JerzyZawadzki: it's not a duplicate because I never asked for a page refresh. Your link doesn't answer my question. It's an acceptable workaround for some people but not a valid answer. – Baylock Aug 01 '13 at 15:26
  • @thatidiotguy: I only want to get rid of the hash if the user opens the website for the first time or refreshes the page. Within the website, the urls must stay as they are. My whole script allows that as it is, only that I get that extra hash after refreshing or opening the website. I can't be positive but I believe that mod_rewrite will get rid of the hashes each time I use the navigation within my website. – Baylock Aug 01 '13 at 15:30
  • Possible duplicate of [How to remove the hash from window.location (URL) with JavaScript without page refresh?](https://stackoverflow.com/questions/1397329/how-to-remove-the-hash-from-window-location-url-with-javascript-without-page-r) – PayteR Sep 10 '17 at 12:54

1 Answers1

3
history.pushState('', document.title, window.location.pathname);

via: Clearing URL hash

Community
  • 1
  • 1
darmce
  • 41
  • 2
  • 1
    also see the 2nd post in http://stackoverflow.com/questions/1397329/how-to-remove-the-hash-from-window-location-with-javascript-without-page-refresh not the accepted answer – darmce Aug 01 '13 at 15:29
  • Thank you, I read all the proposals but this one is not cross browser. I already use this plugin: http://benalman.com/projects/jquery-hashchange-plugin/ which works fine in every single browser I need. My last concern is to get rid of the hash without page refresh and in all major browsers, IE7 and IE8 included. – Baylock Aug 01 '13 at 15:35