Reputation: 47
I figured out how to change url but can i change whole link. For example if user opens stackoverflow.com it will show him exmaple.com. This is the code i've used so far for chaning the URL only:
window.history.pushState(“object or string”, “Title”, “/new-url”);
Upvotes: 0
Views: 267
Reputation: 944444
This is impossible.
pushState
allows you to update the local part of a URL so that you can provide a direct URL to a page that you have constructed piecemeal with JavaScript.
It doesn't let you pretend to be a different website, which would be a serious security risk (as it would make an effective phishing technique). That is why the specification expressly forbids it:
Compare the resulting parsed URL to the result of applying the URL parser algorithm to the document's address. If any component of these two URLs differ other than the path, query, and fragment components, then throw a SecurityError exception and abort these steps.
Upvotes: 2