-1

I have a side with a big number of parameters, like www.hello.com/kaleidoskop.html#look/2

If you reload this side you will still have the parameters.

I would like to delete them and start after refresh with www.hello.com/kaleidoskop.html

For this i made the following:

        function updateHash (t, clean) {
        if (clean) {
            var r = window.location.href.replace(/(javascript:|#).*$/, '');
            window.location.replace(r + '#' + t)
        } else window.location.hash = '#' + t
    }

But here I still have the #.

If I use window.location.replace(r) or window.location.hash = r it loops.

Is there any other solution?

hamburger
  • 1,339
  • 4
  • 20
  • 41

1 Answers1

4

For newer browsers supporting the HTML5 History API:

history.pushState(null, null, location.pathname + location.search);

For older browsers (best you can do without reloading - still keeps the #):

window.location.hash = '';
caub
  • 2,709
  • 2
  • 28
  • 31
jgillich
  • 71,459
  • 6
  • 57
  • 85
  • are you trying to quote andy from http://stackoverflow.com/questions/1397329/how-to-remove-the-hash-from-window-location-with-javascript-without-page-refresh ? – Ejaz May 14 '14 at 18:33
  • @Ejay What are your trying to say, that I copy & pasted my answer? I didn't even read that before, my apologies for having the same idea as someone else. – jgillich May 14 '14 at 18:37
  • no you did not copy, that's not what I am saying :) Since SO tries to reduce duplicate questions, it is better to mark a question duplicate if it can be. – Ejaz May 14 '14 at 18:39
  • sorry for me is this a different answer than Andy E has. It works. thx jgillich – hamburger May 14 '14 at 18:46