Question

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?

Was it helpful?

Solution

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 ;)

OTHER TIPS

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.

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">
Tweet your love of pie!
</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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top