Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple javascript reload not working

Here is the Bin. I am trying to make an example of reloading the page by using location.reload() in the function refresh() and using onclick='refresh()' in a button. For some reason the page is not reloading.

The JS function:

function refresh() {
    location.reload();
}

The HTML button:

<button onclick='refresh()'>Try Refreshing!</button>
like image 353
Joe Pigott Avatar asked Dec 10 '25 21:12

Joe Pigott


1 Answers

Your refresh method is not in the global scope - it's enclosed within your document.ready.

Move it out from document.ready into it's own script tag.

<script>
    function refresh() {
        location.reload();
    }
</script>

The edited bin

like image 54
NG. Avatar answered Dec 13 '25 11:12

NG.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!