简体   繁体   English

网站的Twitter分享按钮

[英]Twitter share button for website

I am trying to implement a twitter share button in my website using the following code 我正在尝试使用以下代码在我的网站中实现Twitter分享按钮

<a class="btn btn-small" href=" https://twitter.com/intent/tweet?source=tweetbutton&text={{name}}&url=https://stage.mutterfly.in+{{url}}" >
      <i class="fa fa-twitter" aria-hidden="true" style="height: 30px; width:30px; color:black"></i>
</a>

where {{text}} is coming from api response and {{url}} is from _route.url which is the current url. 其中{{text}}来自api响应,{{url}}来自_route.url,它是当前URL。 The problem is this link isn't accepting my dynamic data and showing unsafe url error. 问题是此链接不接受我的动态数据并显示不安全的url错误。

How do I insert dynamic text and url into this link and make it work? 如何在此链接中插入动态文本和url并使其起作用?

You can get the value by using a method in the typescript as below, 您可以使用以下打字稿中的方法获取值,

<a class="btn btn-small" 
   [href]="getURL()" >
          <i class="fa fa-twitter" aria-hidden="true" style="height: 30px; width:30px; color:black"></i>
</a>

Your method must be as 您的方法必须为

getURL(){
   return "https://twitter.com/intent/tweet?source=tweetbutton&text=this.name&url=https://stage.mutterfly.in+this.url"
}

You can use this code, i use codeigniter 您可以使用此代码,我使用codeigniter

<?php $url_share ="http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; ?>

<a style="background-color:#16A7F0;padding:5px;color:#FFF;" class="fa fa-twitter" href="https://twitter.com/intent/tweet?text=<?php echo $product['product_name'];?>&url=<?php echo $url_share;?>&via='$youtTags'" onclick="javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=no,scrollbars=no,height=500,width=600');return false;" > Twitter</a>

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

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