微信中打开app store连接

微信浏览器是不支持打开App Store 页面的。比如你页面写 <a href=”http://itunes.apple.com/us/app/id867985717″>下载取号啦</a> ,在微信浏览器点击链接是没有反应的,但是如果是其他的链接地址,比如百度那就没有问题。
function viewSource() {
var redirectUrl = sourceurl.indexOf(‘://‘) < 0 ? ‘http://‘ + sourceurl : sourceurl;
//redirectUrl = http://itunes.apple.com/us/app/id399608199
redirectUrl = ‘http://‘ + location.host + ‘/mp/redirect?url=‘ + encodeURIComponent(sourceurl);
//此处是关键,redirectUrl = http://mp.weixin.qq.com/mp/redirect?url=http%3A%2F%2Fitunes.apple.com%2Fus%2Fapp%2Fid399608199%23rd
var opt = {
url: ‘/mp/advertisement_report‘ + location.search + ‘&report_type=3&action_type=0&url=‘ + encodeURIComponent(sourceurl) + ‘&uin=‘ + uin + ‘&key=‘ + key + ‘&__biz=‘ + biz + ‘&r=‘ + Math.random(),
type: ‘GET‘,
async: !1
};
return tid ? opt.success = function (res) {
try {
res = eval(‘(‘ + res + ‘)‘);
} catch (e) {
res = {
};
}
res && res.ret == 0 ? location.href = redirectUrl : viewSource();
}
: (opt.timeout = 2000, opt.complete = function () {
location.href = redirectUrl;
}),
ajax(opt),
!1;
}
在后台编辑后发现上面的代码真正的url是:http://mp.weixin.qq.com/mp/redirect?url=http%3A%2F%2Fitunes.apple.com%2Fus%2Fapp%2Fid399608199%23rd。这样看,微信允许打开mp.weixin.qq.com这个host下的网页,然后用js再打开真正的页面。利用此原理,,将页面的代码写为:<a href=”http://mp.weixin.qq.com/mp/redirect?url=http%3A%2F%2Fitunes.apple.com%2Fus%2Fapp%2Fid867985717%23rd”>下载取号啦</a>,在微信浏览器内可以打开app store的地址了。
文章来自:http://blog.csdn.net/withiter/article/details/39315553
© 2021 jiaocheng.bubufx.com  联系我们
ICP备案:鲁ICP备09046678号-3