async function downloadVideo(videoUrl) { const downloadBtn = document.querySelector('#downloadBtn'); // 替换为你页面中下载按钮的 selector if (downloadBtn) downloadBtn.innerText = '正在下载中...'; try { // 前端直接请求视频文件 const response = await fetch(videoUrl); const blob = await response.blob(); // 创建本地 Blob URL 触发真正下载 const blobUrl = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = blobUrl; a.download = `video_${Date.now()}.mp4`; document.body.appendChild(a); a.click(); document.body.removeChild(a); URL.revokeObjectURL(blobUrl); if (downloadBtn) downloadBtn.innerText = '下载无水印视频'; } catch (error) { // 如果跨域阻拦,降级方案:在新窗口直接打开视频,提示用户右键另存为 window.open(videoUrl, '_blank'); if (downloadBtn) downloadBtn.innerText = '下载无水印视频'; } }