over 9 years ago
This will change the browser without refreshing and reloading page. In this code I have used four buttons for calling a function to changeUrl concurrently this function will also accepts the page Title and URL as parameters . Below is the example using HTML5 and JS.
- <script type="text/javascript">
- function ChangeUrl(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="Page1" onclick="ChangeUrl('Page1', 'Page1.htm');" />
- <input type="button" value="Page2" onclick="ChangeUrl('Page2', 'Page2.htm');" />
- <input type="button" value="Page3" onclick="ChangeUrl('Page3', 'Page3.htm');" />
- <input type="button" value="Page4" onclick="ChangeUrl('Page4', 'Page4.htm');" />
<script type="text/javascript"> function ChangeUrl(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="Page1" onclick="ChangeUrl('Page1', 'Page1.htm');" /> <input type="button" value="Page2" onclick="ChangeUrl('Page2', 'Page2.htm');" /> <input type="button" value="Page3" onclick="ChangeUrl('Page3', 'Page3.htm');" /> <input type="button" value="Page4" onclick="ChangeUrl('Page4', 'Page4.htm');" />
Can you help out the community by solving one of the following Javascript problems?
Do activity (Answer, Blog) > Earn Rep Points > Improve Rank > Get more opportunities to work and get paid!
For more topics, questions and answers, please visit the Tech Q&A page.
0 Comment(s)