views:

467

answers:

4

I want to display some text on twitter/facebook when a link is clicked on my website. Is there a way in jQuery to do that?

+1  A: 

If you perform an Ajax request to your server when the text was clicked you could post an update to Twitter/Facebook.

EDIT:

JavaScript doesn't allow cross site scripting, so you can't update twitter or Facebook with JavaScript alone. You will need to perform the update from the server side instead of the client side.

For example, you can create a php script that will update twitter and/or Facebook. When a user clicks text on your website, send an Ajax request to that script which will then perform the update.

Trevor
Not sure if I completely understood. But is there a simple way like a jQuery plugin or something like that where I just need to provide the twitter url and the action to be performed or something like that
Pankaj
Edited my answer to answer your question
Trevor
thanks, I guess I got it :)
Pankaj
A: 

Edit, I just saw your comment. You want to post a message on the "clickers" account.

Well firstly, if a twitter window pops up asking me to tweet the fact that I've just clicked a link, I'm leaving your site straight away.

You're much better off letting users decide when they want to tweet something. You could add "tweet this" links but seriously, anything more is just going to drive people nuts.


If you wanted to update your own twitter account when somebody clicked something, you could do the following:

You need two parts to this:

  1. Something on your server that can talk to Twitter or Facebook (there are scripts that do this in a lot of different languages)

  2. Something running in the users browser that looks out for clicks and tells your server to tell Twitter/Facebook something. This would most likely need to be some Javascript event code and some XMLHttpRequest (better known as AJAX).

It's not particularly tough. Google is your friend.

Oli
thanks, I guess I got it :)
Pankaj
A: 

if it's another user posting a message on your own facebook/twitter account, you'll have to store your password on the client side (javascript).
That sounds like a bad idea to me, so you'll have to make it server-side.


So what you'll need is :

  • somebody clicks a link on your website
  • with jQuery, you call a php script which is hosted on your own server
  • that php script posts a message to the twitter/facebook accounts (seems to be pretty difficult, try to find a ready-to-use script.

This way, you can also control the content of the message.

Good luck ;)

Daan
thanks, I guess I got it :)
Pankaj
No problem ;) -
Daan
A: 

If you want to have the user be able to tweet something via a link you can just have your link use the status querystring parameter. So, for example, a link like

<a href="http://twitter.com/home?status=I like pie - http://bit.ly/cKTLx"&gt;
Tweet your love of pie!
</a>
BigPigVT