Javascript 如何仅更改页面URL
我想知道如何在jQuery中将Javascript 如何仅更改页面URL,javascript,jquery,html,Javascript,Jquery,Html,我想知道如何在jQuery中将example.com/file1.html?I=1中的页面URL更改为example.com/file1.html,而无需更改页面内容或重新加载页面。将更改URL而无需重定向或重新加载到file1.html。如果历史推送状态不可用,则使用替代状态 if (history.pushState) { window.history.pushState("{ Object }", "Title", "file1.html"); } else { document.
example.com/file1.html?I=1
中的页面URL更改为example.com/file1.html
,而无需更改页面内容或重新加载页面。将更改URL而无需重定向或重新加载到file1.html。如果历史推送状态不可用,则使用替代状态
if (history.pushState) {
window.history.pushState("{ Object }", "Title", "file1.html");
} else {
document.location.href = "file1.html";
}
作用
function Change(domain, title) {
let url = domain + 'file1.html';
window.history.pushState('data', `{$title}`, url);
document.title = title;
}
我看到这段代码替换了页面内容,我不希望它这样做。如果它不重新加载页面,它如何更改页面内容?@AdelTube没问题