如何在微信瀏覽器內打開App Store鏈接
- 2019 年 11 月 13 日
- 筆記

微信瀏覽器是不支援打開 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 的地址了。
參考鏈接:
聲明:本文由w3h5原創,轉載請註明出處:《如何在微信瀏覽器內打開App Store鏈接》 https://www.w3h5.com/post/313.html