js中是否有任何实用程序或方法可以在按下Windows按钮或任务栏时暂停视频播放?
<html>
<title>Video</title>
<body>
<video id="video" controls>
<source src="http://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4">
</video>
</body>
<script>
var focused = true;
document.addEventListener("visibilitychange", function () {
foo = !foo;
if (!foo)
document.getElementById("video").pause();
});
</script>
</html>
有一种方法。
该答案使用JS / jQuery和对按键的基本了解。
按键就像一个信号,因此每次按下按键时,都会发出一个特定的数字信号,表示按键被按下。
To test keypresses, check HERE.
这是当检测到按键91时可以执行的jQuery函数。
现在,魔术数字键91对应于OS键或“ Windows键”。