skip to Main Content

I am trying to implement a twitter share button in my website using the following code

<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.
The problem is this link isn’t accepting my dynamic data and showing unsafe url error.

How do I insert dynamic text and url into this link and make it work?

2

Answers


  1. You can use this code, i use 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>
    
    Login or Signup to reply.
  2. 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"
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search