实现基于Everwebinar确认页URL参数的定时页面重定向
自定义Everwebinar确认页定时重定向实现
直接用这段JavaScript就能搞定,完全从URL参数里取所需数据:
// 解析URL参数的工具函数 function getUrlParam(name) { // 处理URL里可能存在的双重问号问题(示例URL里有两个?,需要修正) const url = window.location.href.replace(/\?(\w+=)/, '&$1'); const params = new URLSearchParams(url.split('?')[1]); return params.get(name); } // 获取关键参数 const targetTimestamp = getUrlParam('wj_event_ts'); const redirectUrl = getUrlParam('wj_lead_unique_link_live_room'); // 检查参数是否存在 if (targetTimestamp && redirectUrl) { const targetTime = parseInt(targetTimestamp) * 1000; // 转成毫秒级时间戳 const currentTime = Date.now(); const delay = targetTime - currentTime; if (delay > 0) { // 还没到时间,设置定时器 setTimeout(() => { window.location.href = decodeURIComponent(redirectUrl); }, delay); } else if (delay <= 0) { // 已经过了时间,立即跳转 window.location.href = decodeURIComponent(redirectUrl); } } else { // 参数缺失时的提示(可根据需求修改) console.log('缺少必要的URL参数:wj_event_ts 或 wj_lead_unique_link_live_room'); }
关键说明:
- 参数解析处理:示例URL里有两个
?(preview_theme_id=xxx?wj_lead_email=xxx),这不符合标准URL格式,所以函数里先把第一个?后的?替换成&,确保参数能正确解析。 - 时间戳转换:
wj_event_ts是秒级时间戳,需要乘以1000转成JS用的毫秒级时间戳。 - 跳转逻辑:如果当前时间已经晚于目标时间,直接跳转;否则计算延迟时间,到点自动跳转。
- 异常处理:如果参数缺失,会在控制台打印提示,你可以改成页面上的文字提示,比如给某个DOM元素赋值提示内容。
使用方式:
把这段代码放在确认页的<body>标签末尾(或者用DOMContentLoaded包裹放在<head>里),确保页面加载完成后执行。
内容的提问来源于stack exchange,提问作者simonv4549
相关产品推荐
相关产品推荐

