我正在尝试使用pushstate,但它不起作用:
<html>
<head>
<script>function myFunction() {
alert("lel");
var stateObj = { foo: "bar" };
window.history.pushState(stateObj, "page 2", "bar.html");
}
</script>
</head>
<body onload="myFunction()"></body>
</html>
警报出现,所以我知道正在执行该功能,但浏览器的地址栏没有任何反应。为什么呢?
编辑:我使用Firefox,Chrome和IE对此进行了测试。该脚本仅适用于IE而不适用于Firefox或Chrome。答案 0 :(得分:0)
您必须从HTTP服务器请求该页面,而不是直接从磁盘请求,否则它将无法正常工作。谢谢乔纳森。