HTML5历史记录pushState不起作用

时间:2014-07-11 11:03:12

标签: javascript

不确定我做错了什么,但这一小段代码不起作用:

window.history.pushState("foo", "foo", "foo");

它会在 firefox 29 中生成以下错误:

TypeError: window.history.pushState is not a function

2 个答案:

答案 0 :(得分:1)

显然我加入的其中一个脚本有一个声明:

var history = ...;

我不知道,根目录上的所有变量实际上都存在于窗口范围内,因此自定义历史var实际上覆盖了原始window.history。

答案 1 :(得分:0)

请尝试

假设http://mozilla.org/foo.html执行以下JavaScript:

var stateObj = { foo: "bar" };
history.pushState(stateObj, "page 2", "bar.html");

它应该按照Mozzila的说法运作。

请在Mozilla Link

上找到更多信息