You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

JavaScript新手求助:响应播放视频+onend触发页面跳转代码示例

没问题,直接给你写好代码了,你只需要把your-video-file.mp4换成你实际的视频路径就行:

完整代码示例
<!DOCTYPE HTML>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Video Play & Redirect on Task End</title>
</head>
<body>
    <!-- 视频播放器 -->
    <video id="taskVideo" width="640" height="480" controls>
        <source src="your-video-file.mp4" type="video/mp4">
        你的浏览器不支持视频播放。
    </video>

    <script>
        // 这里的const对应你的响应执行任务,替换成你实际的业务逻辑即可
        const executeResponseTask = async () => {
            const videoElement = document.getElementById('taskVideo');
            // 响应任务开始时播放视频
            videoElement.play();

            // 模拟响应执行的耗时操作(把这行换成你真实的响应代码,比如接口请求)
            await new Promise(resolve => setTimeout(resolve, 5000)); // 示例:等待5秒模拟任务执行

            // 任务结束后触发自定义的onend事件
            const endEvent = new Event('onend');
            document.dispatchEvent(endEvent);
        };

        // 监听onend事件,触发页面跳转
        document.addEventListener('onend', () => {
            window.location.replace('https://www.google.com');
        });

        // 启动响应任务
        executeResponseTask();
    </script>
</body>
</html>

内容的提问来源于stack exchange,提问作者B.Ashcroft

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 08:04:39