To modify the URL without reloading,a pushState method has come in HTML5 which is quite same as window.location but does not refresh or reloads the page.
This method will first check if the browser supports HTML5,then the state object containing the title and url is created. It takes three parameters:
1.stateobject
2.Title
3.url
Here is the code :-
<script type="text/javascript">
function ModifyUrl(title, url) {
if (typeof (history.pushState) != "undefined") {
var obj = { Title: title, Url: url };
history.pushState(obj, obj.Title, obj.Url);
} else {
alert("Browser does not support HTML5.");
}
}
</script>
<input type="button" value="First page" onclick="ModifyUrl('First page', 'First_page.html');" />
<input type="button" value="Second page" onclick="ModifyUrl('Second page', 'Second_page.html');" />
0 Comment(s)