12

I have window.history.replaceState(null, null, 'about'); in main.js which are located in required/javascripts on my server.

Then on the about page (located in / (root) on my server), I have a link that uses window.history.replaceState(null, null, 'about:me'); on this page. Everything works fine, but when I click on another link with the same function but with about:girlfriend as URL, I'm getting this error message:

Uncaught SecurityError: Failed to execute 'pushState' on 'History': A history state object with URL 'about:girlfriend' cannot be created in a document with origin 'http://my.domain.com'.

I don't know why my browser (latest version of Chrome) think I'm trying to reach this page using pushState and I don't know why I'm getting this error message, no matter how many times I've read it. Can someone please explain this for me? I do not use History.js for this.

Worth mention, is that I'm not getting this error message if I change : to something else, like - or /. I want to use : because / is not working (404 Page Not Found) and - doesn't fit in - it's better with :.

Airikr
  • 5,214
  • 12
  • 50
  • 100
  • Did you ever solve this, because I've got the exact same problem in my project right now. – najk Oct 07 '14 at 11:54
  • 5
    possible duplicate of [Javascript history.PushState not working?](http://stackoverflow.com/questions/20079704/javascript-history-pushstate-not-working). Also, note, that you will get this error if you are trying to view the webpage locally. The page needs to go thru an HTTP server to work, so if you just open up index.html in your browser from your hard-drive you will get this error. – davidcondrey Nov 22 '14 at 22:35

1 Answers1

7

If you are trying to do this locally, the following works for both locally and remote loaded pages:

history.replaceState(null,null, window.location.pathname + "your thing here")
Nishanthi Grashia
  • 9,645
  • 5
  • 41
  • 55
user5258091
  • 71
  • 1
  • 2