html微信瀏覽器分享顯示圖片的問題


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>demo</title>
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
    <script>
        var imgUrl = "http://musicdata.baidu.com/data2/pic/115424459/115424459.jpg"; 

        var lineLink = "http://www.hougelou.com";
        var descContent = "描述"; //分享給好友的時候顯示標題和描述,分享到朋友圈只顯示標題
        var shareTitle = "阿貓的demo";
        var appid = "";

        var share = {
            shareFriend: function () {
                WeixinJSBridge.invoke('sendAppMessage', {
                    "appid": appid,
                    "img_url": imgUrl,
                    "img_width": "200",
                    "img_height": "200",
                    "link": lineLink,
                    "desc": descContent,
                    "title": shareTitle
                }, function (res) {
                    //_report('send_msg', res.err_msg);
                })
            },
            //分享到朋友圈
            shareTimeline: function () {
                WeixinJSBridge.invoke('shareTimeline', {//
                    "img_url": imgUrl,
                    "img_width": "200",
                    "img_height": "200",
                    "link": lineLink,
                    "desc": descContent,
                    "title": shareTitle
                }, function (res) {
                    //_report('timeline', res.err_msg);
                });
            }
        }


        document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {// 

            //發送給好友
            WeixinJSBridge.on('menu:share:appmessage', function (argv) {
                share.shareFriend();
            });
            //分享到朋友圈
            WeixinJSBridge.on('menu:share:timeline', function (argv) {
                share.shareTimeline();
            });

        }, false);



    </script>
</head>
<body>
hello,world!

</body>
</html>

以上的分享,可以為html分享的時候指定分享縮略圖和標題以及描述。

分享朋友圈:只顯示縮略圖和標題。

 

分享給好友:顯示縮略圖、標題、描述

 

 

js里的imgUrl、lineLink、descContent、shareTitle分別代表縮略圖地址、分享網頁地址、分享描述文字、分享標題

以上測試是在魅族(安卓) wechat 6.0環境。

 

但是在IOS iphone 4s和iPhone6 plus的微信里。看到是這樣的:

顯然,這個顯示的是網頁地址和html文件的document里的title,而且沒有顯示縮略圖。經過測試,發現iphone5s則可以顯示和安卓手機一樣。

 

 

————————————————————————————

那么改成這樣呢:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>demo</title>
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
</head>
<body>
hello,world!
<img src="http://musicdata.baidu.com/data2/pic/115424459/115424459.jpg" />
</body>
</html>

即什么js代碼都沒有,就是一個普通的html網頁,其中放置一個img標簽圖片。

這個時候分享給好友,在魅族(安卓)、iphone4s、和iPhone6 plus里顯示。你可以看到顯示網頁地址和html里document的title和html里的第一張圖片(當有多個<img>的時候獲取第一個,當圖片是gif格式的時候iphone4s不能顯示縮略圖,iphone5s可以,魅族(安卓)也可以)。

 

 

-----------------------------------------------------------------------

結論:js的分享方法不能兼容ios的某些版本。但是如果html里有img標簽,且不是gif格式,則安卓和ios都可以顯示title和img的圖片縮略圖。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM