Skip to content

Instantly share code, notes, and snippets.

@StarrWulfe
Created October 19, 2010 06:16
Show Gist options
  • Save StarrWulfe/633705 to your computer and use it in GitHub Desktop.
Save StarrWulfe/633705 to your computer and use it in GitHub Desktop.
This script makes a bitly URL for your page and places it in a textbox ready for cut & pasting.
<!-- BEGIN Bit.ly Link shortener Callout script **this goes just after </HEAD> in the <BODY> section of the HTML page, template, wherever. This is the actual script that sends the page info to Bit.ly for shortening.** -->
<script charset='utf-8' src='http://bit.ly/javascript-api.js?version=latest&amp;login=YOUR_BITLY_LOGIN_HERE&amp;apiKey=YOUR_API_KEY_HERE' type='text/javascript'/>
<script charset='utf-8' type='text/javascript'>
BitlyClient.addPageLoadEvent(function(){
BitlyCB.myShortenCallback = function(data) {
// this is how to get a result of shortening a single url
var result;
for (var r in data.results) {
result = data.results[r];
result[&#39;longUrl&#39;] = r;
break;
}
document.getElementById(&quot;shorturl&quot;).innerHTML = &quot;Share this link: &lt;input type=&#39;text&#39; value=&#39;&quot; + result[&#39;shortUrl&#39;] + &quot;&#39; name=&#39;bitlyurl&#39;/&gt;&quot;;
}
BitlyClient.shorten(document.location, &#39;BitlyCB.myShortenCallback&#39;);
});
</script>
<!--END Bitly Callout Script -->
<!-- Bit.ly URL BEGIN (place this where you want the shortURL form to show up-->
<div>
<b:if cond='data:blog.pageType == &quot;item&quot;'><form id='shorturl'/></b:if>
</div>
<!-- Bit.ly URL END -->
@christian02108452
Copy link

****<script charset='utf-8' src='http://bit.ly/javascript-api.js?version=latest&login=YOUR_BITLY_LOGIN_HERE&apiKey=YOUR_API_KEY_HERE' type='text/javascript'/>

<script charset='utf-8' type='text/javascript'> BitlyClient.addPageLoadEvent(function(){ BitlyCB.myShortenCallback = function(data) { // this is how to get a result of shortening a single url var result; for (var r in data.results) { result = data.results[r]; result['longUrl'] = r; break; } document.getElementById("shorturl").innerHTML = "Share this link: <input type='text' value='" + result['shortUrl'] + "' name='bitlyurl'/>"; } BitlyClient.shorten(document.location, 'BitlyCB.myShortenCallback'); }); </script>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment