我在搜索切换标签时搜索暂停/播放视频的方法很多,我尝试使用此代码,但它不起作用 控制台中没有错误,我无法找出问题所在
var video = document.getElementById("myvideo");
var documentTitle = document.title;
var updateTitleForVideo = function(state) {
if (state === '') {
document.title = documentTitle;
return;
}
document.title = documentTitle + '[' + state + ']';
};
video.onpause = function() {
updateTitleForVideo('Paused');
};
video.onplay = function() {
updateTitleForVideo('');
}
document.addEventListener('visibilitychange', function() {
var state = document.visibilityState;
if (!video.paused) {
if (state === 'hidden') {
video.pause();
updateTitleForVideo();
}
}
});