Dear all,
I was given a task to generate dynamic url using javascript, After going through all the aspects I decided to work with history object available in javascript. Almost every modern browser today supports modern techniques used in html5. There are basically two methods, Apart from external plugins for url rewriting we can use these inbuilt javascript functions.
1. PushState as the name suggests pushes the history object in the history, just like stack push. It adds the object in the history object which is taken automatically by the browser. The first object is taken as the current object. For Instance,
window.history.pushState(null, response.pageTitle, '/developer/consturction/House');
Here, the statObj is an object which is the object taking the object value. Next parameter is page title and last parameter is urlPath is path which is displayed on the browser.
This is used in most of the cases when the url is to be created dynamically based on user action on the browser without page post back or reload. In the above example, When executed the URL of the browser will become, http(s)://yourdomain/developer/construction/House.
2 ReplaceState as the name suggests, it replaces the exising object with a new object. For example,
window.history.replaceState(stateObj,response.pageTitle,urlPath);
Here the parameters are the same except for the functionality.
Thanks
Ritesh
I was given a task to generate dynamic url using javascript, After going through all the aspects I decided to work with history object available in javascript. Almost every modern browser today supports modern techniques used in html5. There are basically two methods, Apart from external plugins for url rewriting we can use these inbuilt javascript functions.
1. PushState as the name suggests pushes the history object in the history, just like stack push. It adds the object in the history object which is taken automatically by the browser. The first object is taken as the current object. For Instance,
window.history.pushState(null, response.pageTitle, '/developer/consturction/House');
Here, the statObj is an object which is the object taking the object value. Next parameter is page title and last parameter is urlPath is path which is displayed on the browser.
This is used in most of the cases when the url is to be created dynamically based on user action on the browser without page post back or reload. In the above example, When executed the URL of the browser will become, http(s)://yourdomain/developer/construction/House.
2 ReplaceState as the name suggests, it replaces the exising object with a new object. For example,
window.history.replaceState(stateObj,response.pageTitle,urlPath);
Here the parameters are the same except for the functionality.
Thanks
Ritesh