我希望能夠在確認頁面 URL 中包含的給定日期和時間將自定義 Everwebinar 確認頁面(在我的域上)訪問者重定向到特定 URL。
確認頁面 URL 如下所示:
https://website.com/pagename?preview_theme_id=2151207349?wj_lead_email=email@outlook.com&wj_lead_first_name=FirstName&wj_lead_last_name=LastName&wj_lead_phone_country_code=&wj_lead_phone_number=&wj_lead_unique_link_live_room=https://event.webinarjam.com/go/live/1/k6znqu2twiyznhp42&wj_event_ts=1658918700&wj_event_tz=Europe/London&wj_next_event_date=Wednesday, 24 August 2022&wj_next_event_time=2:00 PM&wj_next_event_timezone=London GMT +1
只要重定向日期、時間和 URL 都是從上面的確認頁面 URL 中提取的,那么簡單的 javascript 重定向就很合適,因為每個訪問者都有一個唯一的 URL。
預先感謝您的幫助。
uj5u.com熱心網友回復:
首先需要注意的是,您作為示例給出的確認頁面 URL包含兩個問號,這是無效的。這可能是一個錯字,但 URL 搜索引數前應該只有一個問號,所有搜索引數都用 & 號分隔。
話雖如此,有幾種方法可用于獲取 URL 搜索引數的值,然后根據 URL 中提供的日期/時間進行重定向。這里主要使用的是URLSearchParams(),它允許您獲取一個包含所有可用搜索引數的物件。從那里,wj_event_ts是一個時間戳,可用于比較日期/時間。
對于此示例,我將使用您提供的 URL,但如果此 JavaScript 正在該確認頁面上運行,我已注釋掉如何獲取當前 URL。
// If run on the actual confirmation page, use:
// let currentURL = window.location.href;
let currentURL = new URL("https://website.com/pagename?preview_theme_id=2151207349&[email protected]&wj_lead_first_name=FirstName&wj_lead_last_name=LastName&wj_lead_phone_country_code=&wj_lead_phone_number=&wj_lead_unique_link_live_room=https://event.webinarjam.com/go/live/1/k6znqu2twiyznhp42&wj_event_ts=1658918700&wj_event_tz=Europe/London&wj_next_event_date=Wednesday, 24 August 2022&wj_next_event_time=2:00 PM&wj_next_event_timezone=London GMT +1"),
searchParams = new URLSearchParams(currentURL.search),
nextEventDate = new Date(`${searchParams.get("wj_next_event_date")} ${searchParams.get("wj_next_event_time")} ${searchParams.get("wj_next_event_timezone").substr(searchParams.get("wj_next_event_timezone").indexOf("GMT"))}`);
if(Date.now() >= searchParams.get("wj_event_ts")*1000) {
// It is currently past the date in the URL
console.log("Redirecting... Current Event");
//window.location.href = searchParams.get("wj_lead_unique_link_live_room");
}
// If you want to use the next_event_date value instead, use this section
if(Date.now() >= nextEventDate.getTime()) {
console.log("Redirecting... Next Event");
//window.location.href = searchParams.get("wj_lead_unique_link_live_room");
}
編輯 看起來您在 URL 中有多個日期,并且沒有指定您要使用的日期/時間。我添加了另一個注釋掉的部分以使用next_event_date值而不是event_date時間戳。
uj5u.com熱心網友回復:
我使用了另一種獲取 URL 引數的方法,并且有效。
const queryString = window.location.search;
console.log(queryString);
const urlParams = new URLSearchParams(queryString);
if (urlParams.has('wj_event_ts')) {
if(Date.now() >= urlParams.get('wj_event_ts')*1000) {
// It is currently past the date in the URL
console.log('Redirecting... Current Event');
window.location.href = urlParams.get('wj_lead_unique_link_live_room');
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/505687.html
標籤:javascript 重定向
下一篇:單擊div元素打開一個新頁面
