【发布时间】:2019-01-06 09:46:17
【问题描述】:
我正在尝试使用 window.history.pushState() 来实现无缝页面转换,以更改地址栏中的 url。我关注了这个tutorial,但是pushState抛出了以下错误:Uncaught DOMException: Failed to execute 'pushState' on 'History': A history state object with URL [link] cannot be created in a document with origin 'null' and URL
有谁知道如何解决这个问题。我想要实现的是,获取被点击按钮的href并将url例如从:http://www.example.com/index.html更改为http://www.example.com/about.html。
$('.button').on('click', function(e) {
e.preventDefault();
var href = $(this).attr('href');
window.history.pushState(null, null, href);
$.ajax({
url: href,
success: function(data) {
// Do animation and change content
}
});
});
【问题讨论】:
标签: javascript jquery transition