gpt4 book ai didi

javascript - 基于设备的链接重定向

转载 作者:行者123 更新时间:2023-12-03 08:30:29 24 4
gpt4 key购买 nike

我的电子邮件中有一个链接,指向 xxx.xxxxxxx.xx/zzz 处的视频,其中 zzz 是该视频的唯一 ID。我需要根据用户的设备将用户重定向到正确的位置。如果他们来自 iPhone,它会将他们引导至深层链接。否则,将他们定向到原始网址。

我有以下内容将位于从电子邮件链接到的页面中,但它不太正确:

var host = document.location.hostname + document.location.pathname;

if(navigator.userAgent.match("iPhone") || navigator.userAgent.match("iPad")){
deep link to redirect to here
}
else {
window.location.replace(host);
}

作为图表:

电子邮件链接 -> 设备重定向 -> 如果是 iphone || ipad {转到深层链接} 否则转到视频链接

最佳答案

找出答案:

具有以下格式的原始链接:

<html>
<a href="newsletter-redirect.html?video=http://xxx.xxxxxx.xx/mXp">Video</a>
</html>

newsletter-redirect.html 页面将包含以下 JavaScript:

var video = document.location.search.split("?video=");

if(navigator.userAgent.match("iPhone") || navigator.userAgent.match("iPad")){
window.location.replace("deep link code");
}
else {
window.location.replace(video[1]);
}

这会将用户重定向到链接 http://xxx.xxxxx.xx/mXp如果它们来自非 iOS 设备。

关于javascript - 基于设备的链接重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33356084/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com