Browser Info Nevigator
There are two ways to take the user to a new page using the location object.
First, we can directly set the href property of the object:
location.href = 'www.newpage.com';
Using this technique to transport the user to a new page maintains the original page in the browser’s history list, so the user can return simply by using the browser Back button. If you would rather the sending page were removed from the history list and replaced with the new URL, you can instead use the location object’s replace() method:
location.replace('www.newpage.com');
This replaces the old URL with the new one both in the browser and in the history list.
Reloading the Page
To reload the current page into the browser—the equivalent to having the user click the “reload page” button—we can use the reload() method:
location.reload();
Using reload() without any arguments retrieves the current page from the browser’s cache, if it’s available there. To avoid this and get the page directly from the server, you can call reload with the argument true:
document.reload(true);
While the location object stores information about the current URL loaded in the browser, the navigator object’s properties contain data about the browser application itself.
Try it Yourself: Displaying Information Using the navigator Object
<!DOCTYPE html> <html> <head> <title>window.navigator</title> <style> td {border: 1px solid gray; padding: 3px 5px;} </style> </head> <body> <script> document.write("<table>"); document.write("<tr><td>appName</td><td>"+navigator.appName + " </td></tr>"); document.write("<tr><td>appCodeName</td> <td>"+navigator.appCodeName + "</td></tr>"); document.write("<tr><td>appVersion</td><td>"+navigator.appVersion + "</td></tr>"); document.write("<tr><td>language</td><td>"+navigator.language + " </td></tr>"); document.write("<tr><td>cookieEnabled</td> <td>"+navigator.cookieEnabled + "</td></tr>"); document.write("<tr><td>cpuClass</td><td>"+navigator.cpuClass + " </td></tr>"); document.write("<tr><td>onLine</td><td>"+navigator.onLine + "</td> </tr>"); document.write("<tr><td>platform</td><td>"+navigator.platform + " </td></tr>"); document.write("<tr><td>No of Plugins</td> <td>"+navigator.plugins.length + "</td></tr>"); document.write("</table>"); </script> </body> </html>