ReplaceState (): history state with url ... cannot be created in document with source

I have window.history.replaceState(null, null, 'about'); in main.js that are on 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 a url, I get 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 that I am trying to reach this page using pushState , and I don’t know why I get this error message, no matter how many times I read it. Can anyone explain this to me? I do not use History.js for this.

It is worth noting that I do not receive this error message if I change : to something else, for example - or / . I want to use : because / does not work (404 Page not found) and - does not fit - better with :

+6
source share
1 answer

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

 history.replaceState(null,null, window.location.pathname + "your thing here") 
+4
source

Source: https://habr.com/ru/post/974976/


All Articles