javascript 在自定义 Twitter 共享图标中共享链接、标题和一张图像

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31237839/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 13:30:49  来源:igfitidea点击:

Share the link , title and one image in custom twitter share icon

javascriptjqueryhtmltwittersocial-networking

提问by user782104

Here is the custom twitter icon code:

这是自定义推特图标代码:

HTML:

HTML:

<i id="twitter_share" class="fa fa-twitter fs20" style="position: relative; bottom: 4px;"></i>

And Jquery:

和 Jquery:

$('#twitter_share').click(function (e) {
    e.preventDefault();
    var loc = "<?= base_url(uri_string()); ?>";
    var title = "<?= $video->title; ?>";
    window.open('http://twitter.com/share?url=' + loc + '&text=' + title + '&', 'twitterwindow', 'height=450, width=550, top=' + ($(window).height() / 2 - 225) + ', left=' + $(window).width() / 2 + ', toolbar=0, location=0, menubar=0, directories=0, scrollbars=0');
});

It works fine with the url and title. The problem is , how can I share one image as well?

它适用于 url 和标题。问题是,我怎样才能分享一张图片?

Thanks a lot for helping.

非常感谢您的帮助。

Update: reference in facebook in facebook I can share the content like this, can it be done in twitter as well? Thanks. !

更新:在 facebook 中的参考我可以分享这样的内容,它也可以在 twitter 中完成吗?谢谢。!

facebook share

脸书分享

回答by som

The image comes from your HTML markup, which is scraped by twitter when someone tweets your url.

该图像来自您的 HTML 标记,当有人在推特上发布您的 url 时,该标记会被 twitter 抓取。

Twitter refers to the collection of meta info accompanying a tweet as a card, which they need to approve before it will appear on the network.

Twitter 将随推文附带的元信息集合称为卡片,他们需要批准才能在网络上出现。

  1. Have a good read through the Twitter Cards Developerpage
  2. Select an appropriate card (summary_large_imageis a good one) and include the appropriate twitter meta tags in the head of your HTML
  3. Validate your card on the Cards Validatorpage
  4. Once your domain has been whitelisted any tweets with your url will also include your card
  1. 仔细阅读Twitter 卡片开发人员页面
  2. 选择一张合适的卡片(summary_large_image是一个很好的卡片)并在 HTML 的头部包含合适的 twitter 元标记
  3. Cards Validator页面上验证您的卡
  4. 一旦您的域被列入白名单,任何带有您的 url 的推文也将包含您的卡片

回答by Nico

I searched a little bit for a solution and one Solution is to use Twitter Cards

我搜索了一点解决方案,一个解决方案是使用Twitter Cards

Maybe this thread will help you Twitter - share button, but with image

也许这个线程会帮助你Twitter - 分享按钮,但带有图像