简体   繁体   English

使用JQuery动态共享内容的ShareThis

[英]ShareThis with dynamic share content using JQuery

I'm trying to alter the content shared by ShareThis buttons using JQuery: 我正在尝试使用JQuery更改ShareThis按钮共享的内容:

      var services = [                                                                                                                                                                                                              
          "facebook",                                                                                                                                                                                                               
          "twitter",                                                                                                                                                                                                                
          "linkedin",                                                                                                                                                                                                               
          "email",                                                                                                                                                                                                                  
          "print"                                                                                                                                                                                                                   
      ];                                                                                                                                                                                                                            

      for (var i = 0, len = services.length; i < len; i++) {                                                                                                                                                                        
          stWidget.addEntry({                                                                                                                                                                                                       
              service: services[i],                                                                                                                                                                                                 
              element: document.getElementById("st_data_" + services[i]),                                                                                                                                                           
              url: window.location.href,                                                                                                                                                                                            
              title: $("#lblPropertyTitle").html(),                                                                                                                                                                                 
              type: "large",                                                                                                                                                                                                        
              text: services[i],                                                                                                                                                                                                    
              image: $(".carousel .carousel-inner .item[data-slide-number='0'] img").attr("src"),                                                                                                                                   
              summary: $("#lblPropertyDescription").html()                                                                                                                                                                          
          });                                                                                                                                                                                                                       
      }  

It just shares the base url with the default title and image. 它只是与默认的标题和图像共享基本URL。 How can I alter the title, description and image that it is shared? 如何更改共享的标题,描述和图像?

Facebook and twitter use OG tags to determine the preview image for the url. Facebook和Twitter使用OG标签确定URL的预览图像。 You will need to define those on your page. 您将需要在页面上定义它们。 Defining the image property for the stWidget entry is likely only good for email or print options. 为stWidget条目定义image属性可能仅对电子邮件或打印选项有用。

To define open graph info for the page, add a meta tag like this... 要为页面定义打开的图形信息,请添加这样的元标记...

<meta property="og:url"                content="http://www.nytimes.com/2015/02/19/arts/international/when-great-minds-dont-think-alike.html" />
<meta property="og:type"               content="article" />
<meta property="og:title"              content="When Great Minds Don’t Think Alike" />
<meta property="og:description"        content="How much does culture influence creative thinking?" />
<meta property="og:image"              content="http://static01.nyt.com/images/2015/02/19/arts/international/19iht-btnumbers19A/19iht-btnumbers19A-facebookJumbo-v2.jpg" />

You can validate your OG tags with some web tools. 您可以使用某些网络工具来验证OG标签。

Documentation: 说明文件:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM