[javascript] 定期的にページをリロードする

定期的にページをリロードするには以下のように設定する

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Periodic Page Reload</title>
<style>
    #loadingIndicator {
        display: none;
    }
</style>
</head>
<body>
<h1>Periodic Page Reload</h1>
<button id="stopButton" onclick="stopReload()">Stop Reload</button>
<img id="loadingIndicator" src="https://media.giphy.com/media/3oEjI6SIIHBdRxXI40/giphy.gif" alt="Loading..." width="30px">

<script>
let reloadInterval;

function reloadPage() {
    const loadingIndicator = document.getElementById('loadingIndicator');
    loadingIndicator.style.display = 'inline-block';

    reloadInterval = setInterval(() => {
        location.reload();
    }, 5000);
}

function stopReload() {
    clearInterval(reloadInterval);
    const loadingIndicator = document.getElementById('loadingIndicator');
    loadingIndicator.style.display = 'none';
}

window.onload = reloadPage;
</script>

</body>
</html>

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です