zoukankan      html  css  js  c++  java
  • 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的图片缩略图。

  • 相关阅读:
    moss jscript
    CSS两端对准
    简单的日期格式验证
    .NET中使用Exchange 2007 Webservice来读取邮件
    张二狗
    spcontext
    Infopath表单用改控件值提交或作别的更改时一定要在控件属性浏览器表单的回发设置为始终.
    使用 Web 服务
    SharePoint 2010中开发模式的改进 COM 客户端对象模型
    Retrieve data from Separate Oracle System
  • 原文地址:https://www.cnblogs.com/hougelou/p/4196891.html
Copyright © 2011-2022 走看看