Forum Moderators: open
Also it does not matter if I use <$MTEntryTitle encode_html="0">, <$MTEntryTitle encode_html="1"> or escape(document.title).
Here is the code I am using:
<script type="text/javascript" charset="utf-8" src="http://bit.ly/
javascript-api.js?version=latest&login=LOGIN&apiKey=API_KEY"></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=<$MTEntryTitle encode_html="0">+" + shortURL + "+(via+@example)";
}
</script>
<img src="/images/tweet_this.gif" onClick="BitlyClient.shorten
(document.location, 'BitlyCB.shortenResponse');">
After running the escape(document.title), you could do a .replace() to turn %20 into a plus sign. That should work (of course, so should the %20, so I suspect there's more going wrong here).
This seems to work:
document.location = "http://www.twitter.com/home/?status=Reading:+" + document.title.replace(/ /g,"+") + "+" + shortURL + "+(via+@example)";
However it was just dying when it got to twitter.com. I was not sure if it was because Twitter was being hammered by the DOS attack yesterday or what. I figured it out. My Titles have a space hyphen space in them, creating +-+ in the URL, and it does not like that.
When I click the image, it cannot load Twitter at all. It just sits there and spins, Firefox and Safari. In Safari I am getting the "Safari can't open page" and this is the URL that the script makes:
[twitter.com...]
Though if I just hit return in the URL field, it loads Twitter, places the messages into the Status window, and it is ready to post, right away (in Safari, not Firefox).
I don't get that.
I will have to test it on other computers. But you can test it here:
<snipped url>
[edited by: whoisgregg at 5:16 pm (utc) on Aug. 7, 2009]
[edit reason] Whoops, no URLs please. See TOS [webmasterworld.com] :) [/edit]
The problem with linking to test code/broken code is that those pages tend to get either fixed or pulled down at some point. So someone else who comes along a few weeks from now with the same problem only sees half the details.
By including relevant code snippets in the thread, we make this a much more useful place for all of us.
Glad you got it sorted. :)