0

Let's say I'm on a https://www.example.com. Can I alter address bar URL to display https://www.google.com while I'm in https://www.example.com website using JavaScript?

ex:

I'm on https://www.example.com website, But what if I wanna display different URL like http://www.google.com in the address bar? Is it possible?

Just asking based on learning purpose about the information security.

Kasun
  • 672
  • 8
  • 18

1 Answers1

2

No, that would be a security risk, if any website could make it appear to the user to actually be on any other website. Phishing would be a whole lot easier if that was permitted.

The best you can do is history.pushState (or .replaceState), which has the reasonable restriction that:

The new URL can be any URL in the same origin as the current URL.

Or, of course, you could actually redirect to the other website by assigning to location.href.

It might be possible to write a browser extension that fiddles with the internals of the browser so that it displays your arbitrary desired text instead of the actual current page, but such a thing would have to be deliberately installed by the user.

CertainPerformance
  • 356,069
  • 52
  • 309
  • 320