history.replaceState()的例子吗? [英] history.replaceState() example?

查看:706
本文介绍了history.replaceState()的例子吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何一个可以给一个工作的例子history.replaceState?这是 w3.org 说:

Can any one give a working example for history.replaceState? This is what w3.org says:

历史。 replaceState(数据,标题[,URL])

更新在会话历史具有给定的数据,标题的当前条目,并且,如果提供,并且不为空,网址。

更新:

这完美的作品:

history.replaceState( {} , 'foo', '/foo' );

地址是不断变化的,但标题不发生变化。那是一个错误还是我失去了一些东西?测试在最新的Chrome浏览器。

Url is changing, but title is not changing. Is that a bug or am I missing something? Tested on latest Chrome.

推荐答案

事实上,这是一个错误,虽然有意为2年了。 问题在于一些不明确的规格和复杂性的时候 document.title时键,前进/后退参与。

Indeed this is a bug, although intentional for 2 years now. The problem lies with some unclear specs and the complexity when document.title and back/forward are involved.

查看的Webkit 错误引用和的 Mozilla的。 同时歌剧的引进历史API ​​它不使用标题参数,可能还是没有。

See bug reference on Webkit and Mozilla. Also Opera on the introduction of History API said it wasn't using the title parameter and probably still doesn't.

目前的第二个参数 - 标题   历史进入的 - 没有在Opera的实现中使用,但可能   有一天。

Currently the 2nd argument of pushState and replaceState — the title of the history entry — isn't used in Opera's implementation, but may be one day.

潜在的解决方案

我看到的唯一方法是改变标题元素,并使用pushState来代替:

The only way I see is to alter the title element and use pushState instead:

document.getElementsByTagName('title')[0].innerHTML = 'bar';
window.history.pushState( {} , 'bar', '/bar' );

这篇关于history.replaceState()的例子吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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