Update page with JavaScript
Today we’ll learn how to update our page using the JavaScript function Location.reload
Update page with location.reload
When you run the function the page reloads.
Let´s see an example
location.reload();
Update page with a link
It updates the page when the link is clicked.
Let´s see an example
// Html link code
<a href="javascript:location.reload()">Update page</a>
// The page will reload when the link is clicked
Update page with a button
When the button is clicked the page reloads
Let´s see an example
// Button code
<input type="button" value="Update" onclick="location.reload()"/>
We can give it styles
Let´s see an example
// styled button code
<input type="button" value="Update" onclick="location.reload()"
style="font-family:Arial;font-size:10pt;width:200px;height:30px;
background:#777777;color:#fff444;cursor:pointer;"/>
Update with an interval
Using the setInterval function, the page reloads each 4 seconds, 4000 miliseconds as it´s configured
Let´s see an example
<script type="text/javascript">
// Update function
function update(){
location.reload(true)
}
// Update each 4 seconds function
setInterval("update()",4000);
</script>
Thanks for reading.