Web design and hosting, database, cloud and social media solutions that deliver business results
  • 商务解决方案
  • 数据库咨询服务
    • 报告
      • Claytabase Server Disk IOPs Calculator
      • SQL代码备份
      • SQL打印机
    • 技术文章
      • SQL-Server
      • SQL Server 2008的维护计划
      • 使用SQL Server函数
      • 使用SQL Server日期
      • 使用SQL Server透视-取消透视
  • 网站设计
    • 怀特岛
    • 技术文章
      • ASP-NET
      • CSS
    • 网站安全
  • 产品展示
  • 社交媒体
  • 关于我们
    • 投资组合
    • 球队
      • 切斯特Copperpot
  • 学院
čeština (CS)Deutsch (DE)English (EN-GB)English (EN-US)Español (ES)Français (FR)हिंदी (HI)italiano (IT)日本語 (JA)polski (PL)Português (PT)русский (RU)Türk (TR)中国的 (ZH)

社交媒体Tweet Share Like Follow Buttons for Google Twitter and Facebook

.NET,在C#和VB.NET中创建有或没有Javascript的社交媒体共享按钮

另一种方式 - 没有很多JavaScript

在我原来的博客网站上,我使用下面的代码将一些共享按钮放在一起,但是在我们的新网站上,看起来我们因为缺乏缓存和Javascript的数量而受到惩罚。我现在列出了创建这些按钮的两种方法,一种是JS,另一种是纯代码。

由于这与社交媒体有关,请随时分享!这是截至2015年的100%。

  • 推特
  • Facebook的
  • 谷歌
  • LinkedIn

用Javascript - 旧的方式

这些是你的/按钮。

HTML - Like

<div id="SocialMedia">
<div class="fb-like" data-href="http://www.facebook.com/Claytabase/" data-layout="button_count" data-action="like" data-show-faces="true" data-share="false" style="margin-right:5px;"></div>
<a href="https://twitter.com/Claytabase" class="twitter-follow-button" data-show-count="data-show-count" data-lang="en" data-show-screen-name="false">Claytabase</a>
</div>

另一种方式 - 没有很多JavaScript

现在为了分享按钮的HTML。

HTML - Share

<div id="Share">
<div style="float: left; margin: 0 5px 0 5px;">
    <div id="fbShare" runat="server" clientidmode="Static" class="fb-share-button" data-href="http://www.gsclayton.net" data-type="button_count"></div>
</div>
<div style="float: left; margin: 0 0px 0 5px;">
    <a href="https://twitter.com/share" class="twitter-share-button">Tweet</a>
</div>
<div style="float: left; margin: 0 5px 0 -19px;">
    <div class="g-plus" data-action="share" data-annotation="bubble" align="left">
</div>
</div>
<div style="float: left;">
    <script type="IN/Share" data-counter="right" data-showZero="true"></script>
</div>
<div style="float: left; margin: 0 5px 0 5px;">
    <su:badge layout="1"></su:badge>
</div>
<div style="float: left; margin: 0 5px 0 5px;">
    <a id="PinItButton" runat="server" href="//www.pinterest.com/pin/create/button/?media=http%3A%2F%2Ffarm8.staticflickr.com%2F7027%2F6851755809_df5b2051c9_z.jpg" data-pin-do="buttonPin" data-pin-config="beside"><img src="//assets.pinterest.com/images/pidgets/pinit_fg_en_rect_gray_20.png"/></a></div>
</div>

另一种方式 - 没有很多JavaScript

而现在的JavaScript

JavaScript

<!--Facebook Share andFollow-->
<script type="text/javascript">
    (function (d, s, id) {
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) return;
    js =d.createElement(s); js.id = id;
    js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1";
   fjs.parentNode.insertBefore(js, fjs);
} (document, 'script','facebook-jssdk'));
</script>
<!--Google +1 and Follow-->
<script type="text/javascript">
    (function () {
        var po = document.createElement('script'); po.type = 'text/javascript';po.async = true;
       po.src = 'https://apis.google.com/js/plusone.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
    })();
</script>
<!--Twitter Share-->
<script type="text/javascript">
    !function (d, s, id) {
    var js, fjs = d.getElementsByTagName(s)[0];
    if (!d.getElementById(id)) {
    js =d.createElement(s);
    js.id =id; js.src = "//platform.twitter.com/widgets.js";
   fjs.parentNode.insertBefore(js, fjs);
    }
} (document, "script","twitter-wjs");
</script>
<!--StumbleUpon andPinterest-->
<script type="text/javascript">
    (function () {
    var li = document.createElement('script'); li.type = 'text/javascript';li.async = true;
    li.src =('https:' == document.location.protocol ? 'https:' : 'http:')+ '//platform.stumbleupon.com/1/widgets.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(li, s);
    })();
</script>
<script type="text/javascript" src="//assets.pinterest.com/js/pinit.js"></script>
<!--Linked In Share-->

<script src="//platform.linkedin.com/in.js" type="text/javascript"></script>

另一种方式 - 没有很多JavaScript

如果您将脚本添加到页面底部,则会将其最后加载,从而为您提供更快的加载时间。幸运的是,Facebook,谷歌和Twitter上的人们都在想,并且使用相同的Javascript来分享和像按钮。

LoaderVB

VB

Dim u As String = Replace(Replace(Request.Url.ToString(), " ", "%20"),"http://", "")
If Right(u, 1) = "/" Then
     u = Mid(u, 1, Len(u) - 1)
End If
fbShare.Attributes.Add("data-href",Request.Url.ToString())
Dim p1 As String = "//www.pinterest.com/pin/create/button/?url=http%3A%2F%2F"
Dim p2 As String = "%2F&media=http%3A%2F%2Ffarm8.staticflickr.com%2F7027%2F6851755809_df5b2051c9_z.jpg&"
Dim pd As String = "description=Pin%20claytabase.com%20on%20Pinterest"
PinItButton.HRef = p1 + u + p2 + pd
Dim u As String = Replace(Replace(Request.Url.ToString(), " ", "%20"),"http://", "")
Loader[]

另一种方式 - 没有很多JavaScript

现在我们可以通过这个更快一点,下面是分享的HTML和CSS,并按照按钮。为什么不检查下面的链接如何使用图像精灵CSS?

More: 创建滚动CSS
LoaderFollow

Follow

<div id="FollowBut" runat="server" clientidmode="Static" style="position:relative;width:64px;height:32px;float:right;">
    <img src="https://www.claytabase.co.uk/System/Artwork/Social/Follow.png" alt="share" style="width:64px;height:32px;float:left;" />
    <div id="FollowDiv" style="width:64px;position:absolute;top:0px;right:100%;">
    <a id="LikeFacebook" href="https://www.facebook.com/pages/Claytabase-Ltd/181461242059518" target="_blank" title="Facebook"style="width:64px;float:left;">
    <img src="https://www.claytabase.co.uk/System/Artwork/Social/Facebook.png" alt="Facebook" style="width: 64px; border-radius: 4px;"/></a>
    <a id="LikeTwitter" href="https://twitter.com/claytabase" target="_blank" title="Twitter" style="width: 64px; float: left;">
    <img src="https://www.claytabase.co.uk/System/Artwork/Social/Twitter.png" alt="Twitter" style="width: 64px; border-radius:4px;"/></a>
    <a id="LikeGoogle" href="https://plus.google.com/+ClaytabaseCoUk" target="_blank" title="Google"style="width: 64px;float: left;">
    <img src="https://www.claytabase.co.uk/System/Artwork/Social/Google.png" alt="Google" style="width: 64px; border-radius:4px;"/></a>
    </div>
</div>

另一种方式 - 没有很多JavaScript

这是将共享链接更新到正确页面的代码。我还添加了一些可选的JavaScript,它将在点击中打开一个小窗口。

LoaderVB

VB

Dim DocDesc As String = "en"
Dim DocUrl As String = Request.Url.ToString()
ShareFacebook.HRef = String.Format("https://www.facebook.com/sharer/sharer.php?u={0}",DocUrl)
ShareTwitter.HRef = String.Format("http://twitter.com/share?url={0}&text={1}&via=claytabase",DocUrl, DocDesc)
ShareGoogle.HRef = String.Format("https://plusone.google.com/_/+1/confirm?hl={1}&url={0}",DocUrl, lg)
ShareLinkedIn.HRef = String.Format("http://www.linkedin.com/cws/share?url={0}&original_referer={0}&token=&isFramed=false&lang={1}",DocUrl, lg)
ShareStumble.HRef = String.Format("https://www.stumbleupon.com/submit?url={0}",DocUrl)
ShareEmail.HRef = String.Format("mailto:?subject=I wanted you to see thissite&amp;body=Check out this site {0}", DocUrl)
SharePinit.HRef = String.Format("http://www.pinterest.com/pin/create/button/?url={0}&media=http%3A%2F%2Ffarm8.staticflickr.com%2F7027%2F6851755809_df5b2051c9_z.jpg&guid=XByRQbsL38y8-0&description={1}",DocUrl, DocDesc)

Social Media Share Buttons Optional Javascript

<script type="text/javascript">
    function popupwindow(url, title, w, h) {
    var left = (screen.width / 2) - (w / 2);    
    var top = (screen.height / 2) - (h / 2);    
    return window.open(url, title, 'toolbar=no, location=no, directories=no, status=no,menubar=no, copyhistory=no, width=' + w + ',height=' + h + ', top=' + top + ', left=' + left);
    }
</script>

另一种方式 - 没有很多JavaScript

使用这些来确保当共享项目时,我想要显示的图像首先出现。

Social Media Share Buttons Optional Meta Tags

<meta property="og:image" content="https://www.claytabase.co.uk/Image/ClaytabaseWhiteOnNavy.png"/><meta property="og:site_name" content="Claytabase Ltd"/><link rel="publisher" href=”https://plus.google.com/+ClaytabaseCoUk"/><meta itemprop="image" content="https://www.claytabase.co.uk/Image/ClaytabaseWhiteOnNavy.png"/><meta name="twitter:image:src" content="https://www.claytabase.co.uk/Image/ClaytabaseWhiteOnNavy.png"/><!--<h1>Place this directly belowyour Header 1 Tag, facebook looks for this</h1>--><meta property="og:image" content="https://www.claytabase.co.uk/Image/ClaytabaseWhiteOnNavy.png"/>

另一种方式 - 没有很多JavaScript

如前所述,如果您觉得有用,请分享这一点,并了解每个按钮的工作原理!

作者

Helpful?

Please note, this commenting system is still in final testing.
Copyright Claytabase Ltd 2020

Registered in England and Wales 08985867

RSSLoginLink Cookie政策网站地图

Social Media

facebook.com/Claytabaseinstagram.com/claytabase/twitter.com/Claytabaselinkedin.com/company/claytabase-ltd

Get in Touch

+442392064871info@claytabase.comClaytabase Ltd, Unit 3d, Rink Road Industrial Estate, PO33 2LT, United Kingdom
此网站上的设置设置为允许所有Cookie。 这些可以在我们的Cookie政策和设置页面上更改。继续使用本网站即表示您同意使用Cookie。
Ousia Logo
Logout
Ousia CMS Loader