javascript - 视频暂停超过1分钟后重定向到新页面

标签 javascript jquery video.js

我正在使用 video.js 构建一个自定义视频播放器,并尝试创建一个空闲时间函数,在暂停超过 1 分钟后将视频重定向到主页。最简单的方法是什么?

myPlayer.on("pause", function() {
  window.location = "../index.html";
});

最佳答案

您已经完成了大部分工作,只需使用 setTimeout(),请参阅 here了解更多信息。您需要确保在再次单击播放后取消计时器。

代码

//Global timer object, needed so we can clear it
var timer = null;

myPlayer.on("pause", function() 
{
  //Set the time once the player is paused. Note: 60000 is 1 minute
  timer = setTimeout(function(){window.location = "../index.html"}, 60000);
});

myPlayer.on("play", function() 
{
  //If the user clicks play stop the timer
  //You may need to use this code in other events
  clearTimeout(timer);
});

关于javascript - 视频暂停超过1分钟后重定向到新页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29264754/

相关文章:

javascript - easeljs 舞台宽度和高度是其指定值的一半

javascript - 浏览 DOM : selecting ul childrens

css - Video.js更改焦点样式

javascript - video.js 使用 jQuery 动态改变颜色

video.js 无法在直播中倒带

javascript - 如何获取我的 nodemailer 电子邮件作为变量?

javascript - 计算字符串差异作为范围

javascript - jQuery 中的默认 .toggle() 缓动动画不起作用

javascript - 当元素包含类时如何选中复选框?

jquery - 为什么我隐藏的 <tr> 没有真正隐藏?