使用新 URL 更新地址栏,无需散列或重新加载页面 [英] Updating address bar with new URL without hash or reloading the page

查看:29
本文介绍了使用新 URL 更新地址栏,无需散列或重新加载页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要么梦想着 chrome(开发频道)实现一种通过 javascript(路径,而不是域)更新地址栏的方法,而无需重新加载页面,要么他们真的做到了.

I either dreamt about chrome (dev channel) implementing a way to update the address bar via javascript (the path, not domain) without reloading the page or they really have done this.

但是,我找不到我认为我读过的文章.

However, I can't find the article I think I read.

我疯了还是有办法做到这一点(在 Chrome 中)?

Am I crazy or is there a way to do this (in Chrome)?

附言我不是在谈论 window.location.hash 等.如果上述情况存在这个问题的答案将是不真实的.

p.s. I'm not talking about window.location.hash, et al. If the above exists the answer to this question will be untrue.

推荐答案

您现在可以在大多数现代"浏览器中执行此操作!

这是我阅读的原始文章(发表于 2010 年 7 月 10 日):HTML5:在不刷新页面的情况下更改浏览器 URL.

Here is the original article I read (posted July 10, 2010): HTML5: Changing the browser-URL without refreshing page.

更深入地了解 pushState/replaceState/popstate(又名 HTML5 History API)查看 MDN 文档.

For a more in-depth look into pushState/replaceState/popstate (aka the HTML5 History API) see the MDN docs.

TL;DR,你可以这样做:

TL;DR, you can do this:

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

查看我对 修改 URL 而不重新加载页面的回答 了解基本操作方法.

See my answer to Modify the URL without reloading the page for a basic how-to.

这篇关于使用新 URL 更新地址栏,无需散列或重新加载页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆