In this video, we'll learn how to check if the user is currently on a webpage using JavaScript. We'll cover two different methods for doing this: window.onfocus and window.onblur events. We'll also discuss the pros and cons of each method and how to use them in your code. By the end of this video, you'll have a better understanding of how to detect when the user is viewing your webpage, and you'll be able to use this information to create more engaging and interactive web experiences. I have posted many videos and articles before related to the JavaScript project, now this the something new that we are going to build.
Video Tutorial of How to check the user is on the webpage or not
As you have seen on the given video tutorial of How to play m3u8 file in html video player using JavaScript,
If you are feeling bored watching the given video tutorial of How to play m3u8 file in html video player using JavaScriptthen you can copy or download the given codes below:
How to check the user is on the webpage or not using JavaScript | Free Source Code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Check the user is on the wabpage or not</title>
<style>
*{
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: sans-serif;
}
body {
background: #222;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
}
#video{
width: 600px;
height: 100%;
outline: none;
border: none;
border-radius: 10px;
}
</style>
</head>
<body>
<video src="./video" id="video"></video>
<script>
const video = document.querySelector("#video")
window.addEventListener("focus",()=>{
console.log("The user is currently on the webpage")
video.play();
})
window.addEventListener("blur",()=>{
console.log("The user is not currently on the webpage")
video.pause();
})
</script>
</body>
</html>
Post a Comment
How can I help you