How can I modify URL of a web page without reloading the complete page? Is it even possible using javascript or jquery?
I don't want to change the complete URL, just want to change URL after domain, i.e after https://www.test.com/change-from-here
thank you
Yes, you can change url of browser without loading the web page using javascript window.
history
.pushstate
, here is a example code which can help you
function AjaxSuccess(response, newUrl){
document.getElementById("BodyContent").innerHTML = response.html;
document.title = response.pageTitle;
window.history.pushState({"html":response.html,"pageTitle":response.pageTitle},"", newUrl);
}
In html5 new methods were introduced and you can use history.replaceState() and history.pushState() to change url of web browser without loading it, as these methods allow your to modify history of web browser
Read this article for more details of changing browser history
Yes, You can change history/URL of web browser without reloading it, your problem can be solved by implementing the History API, by using history.pushState() as mentioned in above answer
history.pushState('', 'Page Title', newURL);
check this working example here
hope this helps, thanks
Using HTML5 history.pushState()
and history.replaceState()
methods, which allow you to add and modify history entries, respectively.
window.history.pushState('newpage', 'Title', '/newpage.html');
Using pushState()
changes the referrer that gets used in the HTTP header for XMLHttpRequest objects created after you change the state.
history.replaceState()
operates exactly like history.pushState()
, except that replaceState() modifies the current history entry instead of creating a new one.
Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly