当我在不同的网站时,如何更改地址栏 URL?

How to alter address bar URL while I'm in a different website?

假设我在 https://www.example.com。当我在 https://www.example.com 网站使用 JavaScript 时,我可以更改地址栏 URL 以显示 https://www.google.com 吗?

例如:

我在 https://www.example.com 网站上,但是如果我想在地址栏中显示不同的 URL 像 http://www.google.com 怎么办?可能吗?

只是出于学习目的询问信息安全。

不,如果任何网站可以让用户看起来实际上是在任何其他网站上,那将是一个安全风险。如果允许的话,网络钓鱼会容易得多。

你能做的最好的是history.pushState(或.replaceState),它有合理的限制:

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

或者,当然,您实际上可以通过分配给 location.href 来重定向到其他网站。

也许可以编写一个浏览器扩展来摆弄浏览器的内部结构,以便它显示您想要的任意文本而不是实际的当前页面,但是用户必须故意安装这样的东西.