开发者

Refreshing page on click of a button

开发者 https://www.devze.com 2023-02-21 04:49 出处:网络
I would like to refresh the current page when a button is clicked. Using JavaScript, I have th开发者_高级运维e following:

I would like to refresh the current page when a button is clicked.

Using JavaScript, I have th开发者_高级运维e following:

<button type="button" onClick="refreshPage()">Close</button>

<script>
    function refreshPage() {
        // What do I put here?
    } 
</script>

What would to code look like to refresh the current page?


<button type="button" onClick="refreshPage()">Close</button>

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

or

<button type="button" onClick="window.location.reload();">Close</button>


There are several ways to reload the current page using a button or other trigger. The examples below use a button click to reload the page but you can use a text hyperlink or any trigger you like.

<input type="button" value="Reload Page" onClick="window.location.reload()">

<input type="button" value="Reload Page" onClick="history.go(0)">

<input type="button" value="Reload Page" onClick="window.location.href=window.location.href">


Works for every browser.

<button type="button" onClick="Refresh()">Close</button>

<script>
    function Refresh() {
        window.parent.location = window.parent.location.href;
    }
</script>


This question actually is not JSP related, it is HTTP related. you can just do:

window.location = window.location;


I'd suggest <a href='page1.jsp'>Refresh</a>.


<button onclick=location=URL>Refresh</button>

Small hack.


Develop Refresher App!
Copy and run!

<!DOCTYPE html>
<html>
<head>
    <title>Refresher App</title>
    <style>
        body {
            text-align: center;
            background-color: brown;
        }
        #container {
            color: white;
        }
    </style>
</head>
<body>
    <div id="container">
        <h1 id="counter">0</h1>
    </div>
</body>
<script>
    var counter = document.getElementById("counter").textContent;
    //For Counter
    setInterval(function () {
        counter++;
        document.getElementById("counter").textContent = counter;
    }, 1000);
    //For Reload
    setInterval(function () {
        window.location.reload();
    }, 10000)
</script>
</html>


You can easily add Location reload() Method

// What do I put here?
   location.reload();
0

精彩评论

暂无评论...
验证码 换一张
取 消