Forum Moderators: open
<script type="text/javascript" charset="utf-8" src="http://bit.ly/javascript-api.js?version=latest&login=LOGIN&apiKey=APIKEY"></script>
<script type="text/javascript">
BitlyCB.shortenResponse = function(data) {
var s = '';
var first_result;
// Results are keyed by longUrl, so we need to grab the first one.
for (var r in data.results) {
first_result = data.results[r]; break;
}
// Now get the shortURL
shortURL = first_result["shortUrl"];
document.location = "http://www.twitter.com/home/?status=" + document.title.replace(/ /g,"+") + "+" + shortURL + "+(via+@example)";
}
</script>
<img style="cursor: pointer;" src="/images/tweet.gif" title="Tweet about <$MTEntryTitle encode_html="0">" onClick="BitlyClient.shorten(document.location, 'BitlyCB.shortenResponse');">
window.open ("http://www.example.com","mywindow");
Now if I put that on an onClick event, it works. I just do not know how to make it work with the above code, after changing document.location in both places in the script.
So, can you help me out here?
document.location = "http://www.twitter.com/home/?status=" + document.title.replace(/ /g,"+") + "+" + shortURL + "+(via+@example)";
And change it up to call window.open instead:
windowOpenUrl = "http://www.twitter.com/home/?status=" + document.title.replace(/ /g,"+") + "+" + shortURL + "+(via+@example)";
window.open(windowOpenUrl, 'new_window', 'width=600,height=400');
The other place you have document.location you want to leave how it is. That part sends the current URL to your URL shortening service so it can generate a new short URL. :)
I'm not sure the best way to get around this... legitimate uses for window.open sometimes require the user to temporarily turn off their pop-up blocker.