-
-
Save fhefh2015/be4f77427b02c041bf9b4e76b7745645 to your computer and use it in GitHub Desktop.
调用微信内置图片查看
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 方法1 | |
* 调用微信内置浏览器查看图片功能 | |
* current - 查看图片的 url | |
* urls - 查看图片 url 集合 | |
*/ | |
function imagePreview(current, urls) { | |
// 解析相对路径 | |
var anchor = document.createElement('a'); | |
function parseUrl(url) { | |
anchor.href = url; | |
return anchor.href; | |
} | |
current = parseUrl(current); | |
for (var i = 0; i < urls.length; i++) { | |
urls[i] = parseUrl(urls[i]); | |
} | |
// 调用 WeixinJSBridge imagePreview | |
typeof WeixinJSBridge !== 'undefined' && WeixinJSBridge.invoke('imagePreview', { | |
current: current, | |
urls: urls | |
}, function() {}); | |
} | |
/** | |
* 方法2 | |
* 调用微信内置浏览器查看图片功能 | |
* <a href="weixin://viewimage/后面你的图片地址">balabala</a> | |
* <a href="weixin://viewimage/http://www.baidu.com/img/bdlogo.gif">balabala</a> | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment