【发布时间】:2019-07-27 22:32:49
【问题描述】:
我正在为付费搜索设置一个页面(仅限移动设备),我想在其中检测用户的操作系统,并在页面加载时将他们重定向到基于操作系统的另一个链接。我的检测和重定向工作良好,但我希望能够从引用源中获取 URL 参数,并附加到重定向 URL。
我基本上希望能够从“?”中获取所有内容。覆盖并附加到下面示例中的 url。
<script>
function getMobileOperatingSystem() {
var userAgent = navigator.userAgent || navigator.vendor || window.opera;
if (/android/i.test(userAgent)) {
return "Android";
}
// iOS detection
if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) {
return "iOS";
}
return "unknown";
}</script>
<script>
function DetectAndServe(){
let os = getMobileOperatingSystem();
if (os == "Android") {
window.location.href = "https://myurl.com[APPENDED PARAMETERS HERE]";
} else if (os == "iOS") {
window.location.href = "https://myurl.com[APPENDED PARAMETERS HERE]";
} else {
window.location.href = "https://myurl.com[APPENDED PARAMETERS HERE]";
}
}
</script>
【问题讨论】:
-
developer.mozilla.org/en-US/docs/Web/API/… 查看window.location.search,然后使用字符串插值将它们与您的重定向URL结合在一起
标签: javascript