Shorten URL using bit.ly (Javascript)
Hello there. For my forum I wish to use Javascript to shortern the page url into a bit.ly URL and then for the bit.ly URL to be put into a Javascript var ready to be called in my twitter re-tweet script.
You can find my current twitter re-tweet script below. At the moment it can get the page URL and title and then tweet these. What I want it the page URL to be first shortened using bit.ly (js) and then the new short-url echoed instead of twtUrl.
Code:
// Variables for twitter to use
var twtTitle = document.title;
var twtUrl = location.href;
var maxLength = 140 - (twtUrl.length + 1);
if (twtTitle.length > maxLength) {
twtTitle = twtTitle.substr(0, (maxLength - 3))+'...';
}
var twtLink = 'http://twitter.com/home?status='+encodeURIComponent(twtTitle + ' ' + twtUrl);
document.write('<a href="'+twtLink+'" target="_blank"'+'>Tweet This!<'+'/a>');
I hope you understand what I mean. Kind regards.