谷歌翻译在浏览器地址栏上书写

发布于 2024-11-27 07:54:37 字数 318 浏览 4 评论 0原文

我刚刚注意到,现在使用谷歌翻译时,当您编写如下内容时,该网站也会实时更新浏览器网址栏:

http://translate.google.com/#en|fr|hello

但页面不会重新加载,正如我在使用 document.location.href=newurl 时所看到的那样

所以,我的问题是:

1 - 他们如何实现这种效果?

2 - 这被认为是一个好的做法吗?我可以看到好处,现在重新加载网站不会使其丢失参数,但它也会使浏览器历史记录变得非常脏,因为还保留了所有中间步骤

提前致谢

I just noticed that now when using Google Translate, the site is updating also the browser url bar in real time when you write something like:

http://translate.google.com/#en|fr|hello

But the page doesn't reload as I am used to see when using document.location.href=newurl

So, my questions are:

1 - How do they achieve this effect?

2 - Is it considered a good practice? I can see the benefits, reloading the site now doesn't make it lose the parameters, but it also makes the browser history quite dirty because is also keeping all the intermediate steps

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

逐鹿 2024-12-04 07:54:37

# 之后的任何内容都不会导致页面重新加载。

Anything after the # doesn't cause the page to reload.

oО清风挽发oО 2024-12-04 07:54:37

您可以使用 location.hash = 'en|fr|hello';

编辑:请参阅 修改 URL 而不重新加载页面

You can use location.hash = 'en|fr|hello';

EDIT: see Modify the URL without reloading the page

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文