×

Index

JavaScript Tutorial

JavaScript Examples

CSS Tutorial

CSS Examples

JavaScript - Function to Refresh Page on Button Click

In this example, we will learn how to refresh current webpage on button click event. Here we are creating a JavaScript function that will refresh webpage on Button Click event.

location.reload(); is used to refresh the page, we will call this method within the JavaScript function with confirmation box.

Refresh Webpage on Button Click

JavaScript function:

<script type="text/javascript">
    function refreshPage() {
        if (confirm("Are you sure, want to refresh?")) {
            location.reload();
        }
    }
</script>

JavaScript and HTML Code to Refresh Page on Button Click

<!--JavaScript - Function to Refresh Page on Button Click.-->
<html>
    <head>
        <title>JavaScript - Function to Refresh Page on Button Click.</title>
        <script type="text/javascript">
            function refreshPage() {
                if (confirm("Are you sure, want to refresh?")) {
                    location.reload();
                }
            }
        </script>
    </head>

    <body style="text-align: center;">
        <h1>JavaScript - Function to Refresh Page on Button Click.</h1>
        <p><input type="button" value="Refresh Webpage." onclick="refreshPage()" /></p>
    </body>
</html>

Result:

refresh page on button click

JavaScript Examples »



Related Examples



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.