Twitter sharing button integration on a static website

I am trying to integrate on my website in JS to short my url. All my url are too long, what will be the most straight foward way to use the restful api for sharing button on a static website in HTML/javascript.

The result I want to get is when my user click share on my website the url is automatically shortened by

here is the code I am currently using to share my pages dynamically on twitter:

 <a href="javascript:tweetCurrentPage()" class="tweetlink">tweet this link</a>

<script type="text/javascript" charset="utf-8" src=""></script>
<script src=""></script>


function tweetCurrentPage()
      {"" + escape(window.location.href) + "&text=" + document.title, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=300,width=600'); return false; }

var TweetThisLink = {

    shorten : function(e) {


        var url = this.href.substr(this.href.indexOf('http:',5))
        BitlyClient.shorten(url, 'TweetThisLink.response');
    response : function(data) {
        var bitly_link = null;
        for (var r in data.results) {
            bitly_link = data.results[r]['shortUrl']; 
        var tweet_text = "I am reading documentation of"
        document.location = "" + encodeURIComponent(tweet_text + ' ' + bitly_link);

jQuery('.tweetlink').bind('click', TweetThisLink.shorten);

please tell me if my question is not clear enough. It’s my first development project I am just trying to learn.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.