Search code examples
javascriptapihistory.js

History pushState throws Uncaught DOMException


So I am using the History API and I am trying to use the pushState() function :

I did this: history.pushState({'a': 'b'}, 'Document', "index2.html");

It gives me this error:

Uncaught DOMException: Failed to execute 'pushState' on 'History': A history state object with URL '...' cannot be created in a document with origin 'null' and URL '...'.


Solution

  • Is it this issue? replaceState() with document origin null

    If so, the answer there indicates that this works:

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