php - Can I include some javascript in a Facebook feed?


I have a Facebook app with which I'd like to display an image in a user's feed. It's just a small circle, which will be different colours depending on what the user does within my app.

Instead of creating lots of different images to display, one for each possible colour the circle could be, it would be ideal if I could put up a PNG with transparency, and then just change the colour by filling a DIV behind the image with Javascript.

However, it's not clear to me if Facebook will allow that in the feed.

Can include some Javascript in the feed, or is that strictly forbidden?

Or is my only option to have a library of images for all the different colours and have a PHP function which selects the right one to output?




Facebook doesn't allow any scriptable content within feed stories, and this isn't possible to implement what you want this way.

You can easily create simple script that will return colored image according to passed arguments and use it as source for the image.

Something like this may provide you some points:

// create a 200*200 image
$img = imagecreatetruecolor(200, 200);

// get the color from URL arguments or use default one
$rgb = isset($_REQUEST['color']) ? $_REQUEST['color'] : 'FFEEDD';

$color = array(
  base_convert(substr($rgb, 0, 2), 16, 10),
  base_convert(substr($rgb, 2, 2), 16, 10),
  base_convert(substr($rgb, 4, 2), 16, 10),

// allocate some colors
$white = imagecolorallocate($img, 255, 255, 255);
$red   = imagecolorallocate($img, $color[0], $color[1], $color[2]);

// draw the head
imagefilledarc($img, 100, 100, 200, 200, 0, 360, $red, IMG_ARC_PIE);

// output image in the browser
header("Content-type: image/png");

// free memory



No, facebook doesn't allow embedding JavaScript in feeds for security reasons. Even if you manage to do it, it won't work because certain characters such as<,>, etc will be converted into html entities which means the JavaScript won't work.

People are also looking for solutions to the problem: php - Writing Complex queries in Amazon Dynamo DB(Mathematical expressions)


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.