How to Redirect to Another Page After 5 Seconds using jQuery?
Today, we will learn How to Redirect to Another Page After 5 Seconds using jQuery. We will use built-in setTimeout(callback, delay)
function takes two parameters a callback and a time in milliseconds. When the setTimeout method is called, the callback function will be executed after the specified time. In this tutorial, I will give you an example of How to Redirect to Another Page After 5 Seconds using jQuery. the below example redirects to another page after 5 seconds and this will happen only one time.
How to Redirect to Another Page After 5 Seconds using jQuery?
Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>How to Redirect to Another Page After 5 Seconds using jQuery?</title>
<script src="https://code.jquery.com/jquery-git.js"></script>
</head>
<body>
<h1>How to Redirect to Another Page After 5 Seconds using jQuery?</h1>
<div class="redirect-to">
<button>Redirect me to devnote laravel category</button>
</div>
<script>
$("button").click(function(){
$(".redirect-to").text("Redirecting...");
setTimeout(function(){
location = "https://devnote.in/laravel";
}, 5000)
})
</script>
</body>
</html>
Output
After 5 seconds, the "https://devnote.in/laravel" page will open.