-5

I need some help. I want to change address bar content, but i need replace whole addres including www.site.com/(domain)

I make a try with:

window.history.pushState("object or string", "Title", "new-url");

But without sucess. Please help?

Thanks

bciric
  • 3
  • 1

1 Answers1

1

The history.pushState api only allows you to modify the url within the same origin, which is <scheme> "://" <hostname> [ ":" <port> ]. The pushState api will allow you to modify the path, query parameters, and url fragment. The reason you can't modify the origin is because of the Same-origin Policy, which provides a guarantee that one origin cannot interfere with another origin. The policy exists to provide security guarantees on the web, such as confining malicious JavaScript to a single origin so it can't affect other websites.

winhowes
  • 7,845
  • 5
  • 28
  • 39
  • this is not solution for my problem, i still can't change address content? You mean its is impossible? – bciric Mar 10 '20 at 09:05
  • Without doing a redirect you can only change the path, query parameters, and fragment. You cannot change the origin without doing a redirect. – winhowes Mar 10 '20 at 18:49