如何在微信浏览器内打开App Store链接

app-store-1024x69.png 如何在微信浏览器内打开App Store链接 经验总结

微信浏览器是不支持打开 App Store 页面的,不知道微信为什么这么做。

比如你页面写 <a href=”http://itunes.apple.com/us/app/id399608199″>download</a> ,在微信浏览器点击是没有反应的,但是如果是其他的链接地址,如百度就没有问题。

但是,如果在微信公众号后台编辑图文,把原文链接写为:http://itunes.apple.com/us/app/id399608199 ,就可以打开。原来微信页面的“查看原文”是一个function,如下:

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%2Fid399608199%23rd">download</a>

就可以在微信浏览器内打开 App Store 的地址了。

参考链接:

实现微信浏览器内打开App Store链接

推荐阅读:

WebStorm怎么设置实现自动编译less文件

jQuery实现元素的鼠标移入移出及点击显示隐藏(微信二维码)

Ueditor后端配置项没有正常加载,上传插件不能正常使用!的解决过程。

Linux下如何重置MySQL密码

判断网页是通过PC端还是移动终端打开的

赞 (0)
分享到: +

评论 沙发

Avatar

换个身份

  • 昵称 (必填)
  • 邮箱 (选填)