how to modify url without reloading page?


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


Asked by:- Vipin
2
: 3707 At:- 7/14/2017 3:01:13 PM
javascript jQuery url-rewriting change-url-without-loading







3 Answers
profileImage Answered by:- manish

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

2
At:- 7/14/2017 3:25:38 PM Updated at:- 12/24/2022 8:11:22 AM


profileImage Answered by:- vikas_jk

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

1
At:- 7/15/2017 8:14:28 AM


profileImage Answered by:- jon

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.

0
At:- 12/24/2022 2:58:08 PM






Login/Register to answer
Or
Register directly by posting answer/details

Full Name *

Email *




By posting your answer you agree on privacy policy & terms of use