It might happen that on a certain event you want to reload a page. The events over which you may want to trigger page reload are click of a button, click of a link, selection of a checkbox.
To reload or refresh a page,
location object is used. Syntax is :
Suppose there is a button on whose click the page needs to be refreshed. Basically, you need to call the above line of code on click of a button. This can be done in two ways :
onclickattribute of button.
- Calling a jQuery click event handler for this button.
Following code demonstrates both these approaches.
Both the approaches do the same task but in different ways.
Let’s tweak in :
locationis a property of
windowobject represents the current open window.
locationobject has all information about the current url. You can use it easily obtain parameters such as the url of current page, its host, port, protocol etc.
reload()function takes an optional
falseparameter. When set to true, it fetches the page from the server rather than the browser cache. The parameter defaults to
false, so by default the page may reload from the browser’s cache.
reload()function does not ask a user for confirmation of page refresh. It just refreshes it.
Hope this post helped to know something additional about the topic. Keep visiting and spreading !!!