views:

30

answers:

2

Hi,
i am trying to add some images to my facebook tab-app via FBJS.

The Problem:
I can't see the images and I don't know why.

The FBJS code

url = "http://www.domain.de/image.gif";
myImg = document.createElement('img');
myImg.setStyle( {backgroundImage: 'url('+url+')' });
document.getElementById('wrapper').appendChild(myImg); 

The rendered html

<img style="background-image: url("http://www.domain.de/image.gif";);"&gt;
A: 

Try modifying your code like this and specify the src attribute of the image:

url = "http://www.domain.de/image.gif";
myImg = document.createElement('img');
myImg.setSrc(url);
document.getElementById('wrapper').appendChild(myImg); 
Sarfraz
This is FBJS (http://developers.facebook.com/docs/fbjs), not pure JavaScript+DOM. (And if it were, no need for `setAttribute`, `src` is a reflected attribute.) **And** he's setting a background image, though that seems weird.
T.J. Crowder
Thanks, myImg.setSrc(url); works fine
fabian
@fabian: Exactly, it is `setSrc`; sorry i forgot, it has been quite some time since i did facebook app development :)
Sarfraz
A: 

You're really thing to set the background image of an img element? That seems...odd. Are you sure you don't just want to do a normal img element (Sarfraz may have you covered there if so) or specify the background image of the wrapper element? E.g.:

url = "http://www.domain.de/image.gif";
document.getElementById('wrapper').setStyle( {backgroundImage: 'url('+url+')' });

I've marked this CW because I've never done any FBJS, so could be talking through my hat. :-) If it helps, it helps.

T.J. Crowder