【发布时间】:2023-01-25 03:00:02
【问题描述】:
此脚本将用户从 facebook 浏览器重定向到 android 设备上的 google chrome,我需要它在以下设备上做同样的事情:
- Android (google chrome) 和 iphone(safari) 上的 Instagram 浏览器
- iPhone 上的 Facebook 浏览器(重定向到 Safari)
这是现在正在运行的代码:
<script>
function isFacebookApp() {
var ua = navigator.userAgent || navigator.vendor || window.opera;
return (ua.indexOf("FBAV") > -1) || (ua.indexOf("FBAN") > -1);
}
if (isFacebookApp()) {
var currentLink = location.href;
if (currentLink.indexOf('https') > -1) {
var currentLink = currentLink.replace('https://', '');
currentLink = currentLink.replace('www.', '');
var chromeLink = "intent://" + currentLink + "#Intent;scheme=https;package=com.android.chrome;end";
window.location.href = chromeLink;
}
if (currentLink.indexOf('http') > -1) {
var currentLink = currentLink.replace('http://', '');
currentLink = currentLink.replace('www.', '');
var chromeLink = "intent://" + currentLink + "#Intent;scheme=http;package=com.android.chrome;end";
window.location.href = chromeLink;
}
}
</script>
谢谢
【问题讨论】:
标签: javascript redirect user-agent