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
: 408 At:- 7/14/2017 3:01:13 PM
javascript jQuery url-rewriting change-url-without-loading






2 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:- 7/15/2017 8:10:14 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





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