简体   繁体   English

如何在不重新加载页面的情况下更改页面URL和页面内容?

[英]How to change page url and page content without reload the page?

I want to do that when I clicked on link (for example test.com/page?=test) my tab in the broswer open the link but without reload or refresh the page and change the content to the page content. 当我单击链接(例如test.com/page?=test)时,我想这样做,浏览器中的选项卡打开了链接,但没有重新加载或刷新页面并将内容更改为页面内容。

How can I start it? 我该如何开始呢? I know PHP, but its the first time that I try to do this. 我知道PHP,但这是我第一次尝试这样做。

You can use HTML5 History API 您可以使用HTML5历史记录API

document.body.addEventListener('click', function(event){
    if(event.target.tagName === 'A'){
       event.preventDefault();
       history.replaceState({}, "Page Title", event.target.href);
    }
})

Well, i doubt there is any easy way for this. 好吧,我怀疑有没有简单的方法可以做到这一点。 https://www.w3schools.com/xml/ajax_intro.asp This might help. https://www.w3schools.com/xml/ajax_intro.asp这可能会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM