EMLOG视频播放屏蔽右键保存和下载共功能能
echo_log.php
找到:
<?php echo $log_content; ?>
修改为:
<!--?php echo parse_admonitions($log_content); ?--> <?php // 为所有video标签添加禁止下载属性,保留其他控件 $log_content = preg_replace('/<video\s+/', '<video controlslist="nodownload" ', $log_content); echo $log_content; ?>
footer.php
在</body>
前添加
<script> // 全局禁用视频元素的右键菜单 document.addEventListener('DOMContentLoaded', function() { // 禁用所有video标签的右键 const videos = document.querySelectorAll('video'); videos.forEach(video => { video.setAttribute('controlslist', 'nodownload'); video.setAttribute('oncontextmenu', 'return false;'); }); // 可选:禁用视频容器的右键(进一步增强) const videoContainers = document.querySelectorAll('.log-content, .page-content'); // 根据实际文章容器类名调整 videoContainers.forEach(container => { container.addEventListener('contextmenu', function(e) { // 若右键目标是视频或视频内元素,则阻止 if (e.target.closest('video, object, embed')) { e.preventDefault(); return false; } }); }); }); </script>
在style.css
中添加
/* 视频保护核心样式 */ .video-protect-container { position: relative; display: inline-block; max-width: 100%; } /* 覆盖层 - 拦截所有右键事件 */ .video-protect-overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 10; /* 确保覆盖层在视频上方 */ pointer-events: auto; /* 捕获所有鼠标事件 */ } /* 全屏状态下隐藏覆盖层,确保控件可用 */ video:fullscreen ~ .video-protect-overlay, video:-webkit-full-screen ~ .video-protect-overlay, video:-moz-full-screen ~ .video-protect-overlay { display: none; pointer-events: none; } /* 隐藏所有浏览器的下载按钮 */ video::-webkit-media-controls-download-button { display: none !important; } video::-webkit-media-controls-enclosure { overflow: hidden !important; } video { --media-controls-download-button-display: none; /* Firefox */ }
网友留言(0 条)