ios app 解决微信扫二维码不能跳转问题

时间:2022-11-17 09:46:39

<script>
(function(){

// Setup GA
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-35169517-1', 'jianshu.com');

// Setup redirect flag
var Maleskine = {
href: '/apps',
search: location.search,
redirected: false,

redirect: function() {
if (Maleskine.redirected) return;

redirected = true;
// window.location.href = Maleskine.href;
window.location.href = Maleskine.href;
},

route: function() {
var ua = navigator.userAgent.toLowerCase();
var defaultBrowser;

if (/iphone|ipad|ipod/.test(ua)) {

// This is iOS.
platform = 'ios';
defaultBrowserName = ' Safari ';

if (/micromessenger|qq|mqqbrowser/.test(ua)) {
// In Weixin, go to QQ yingyongbao.
Maleskine.href = 'http://a.app.qq.com/o/simple.jsp?pkgname=com.jianshu.haruki';
} else {
// Not in Weixin, go to AppStore directly.
Maleskine.href = "https://itunes.apple.com/cn/app/jian-shu/id888237539?ls=1&amp;mt=8";
}

ga('set', 'page', '/download/hugo' + Maleskine.search);
ga('send', 'pageview');
// setTimeout(Maleskine.redirect, 2000);

Maleskine.redirect();
} else if (/android/.test(ua)) {

// This is android.
platform = 'android';
defaultBrowserName = '浏览器';

if (/micromessenger/.test(ua)) {
// In Weixin, go to QQ yingyongbao.
Maleskine.href = 'http://a.app.qq.com/o/simple.jsp?pkgname=com.jianshu.haruki';
} else {
Maleskine.href = 'http://downloads.jianshu.io/apps/haruki/JianShu-1.7.5.apk';
}
ga('set', 'page', '/download/haruki' + Maleskine.search);
ga('send', 'pageview');
// setTimeout(Maleskine.redirect, 2000);

Maleskine.redirect();
} else if (/windows phone|blackberry/.test(ua)) {
// This is other mobile system.
platform = 'other'
ga('set', 'page', '/download/other' + Maleskine.search);
ga('send', 'pageview');
alert('抱歉,我们暂没有推出您手机系统对应的应用。');
location.href = '/';
} else {
platform = 'none'
ga('send', 'pageview');
location.href = '/apps';
}

// if (platform == 'ios') {
// var div = document.createElement('div');
// div.style.clear = 'both';
// div.appendChild(document.createTextNode('正在跳转中···若您正在微信中无法跳转,请点右上角的「···」按钮,选择「在' + defaultBrowserName + '中打开」即可正常跳转噢~'));
// document.body.appendChild(div);
// div = document.createElement('div');
// div.style.float = 'right';
// div.appendChild(document.createTextNode('——— 简书团队'));
// document.body.appendChild(div);
// } else if (platform == 'android') {
// if (defaultBrowserName && /micromessenger/.test(ua)) {
// var div = document.createElement('div');
// div.style.clear = 'both';
// div.appendChild(document.createTextNode('正在跳转中···若您正在微信中无法跳转,请点右上角的「···」按钮,选择「在' + defaultBrowserName + '中打开」即可正常跳转噢~'));
// document.body.appendChild(div);
// div = document.createElement('div');
// div.style.float = 'right';
// div.appendChild(document.createTextNode('——— 简书团队'));
// document.body.appendChild(div);
// }
// }
},
};

// GO!
Maleskine.route()
})()
</script>