Hello world of FBJS

250 views Asked by At

I'm trying to start off using FBJS, and I can't figure this out. The documentation on developer.facebook.com seems so limited and hard to sort through I can't figure out where to find info on this.

Anyway, I'm just trying to do the hello world application shown on facebook

<script> 
<!-- 
function random_int(lo, hi) { 
   return Math.floor((Math.random() * (hi - lo)) + lo); 
} 

function hello_world(obj) { 
   var r = random_int(0, 255), b = random_int(0, 255), g = random_int(0, 255); 
   var color = r+', '+g+', '+b;
   obj.setStyle('color', 'rgb('+color+')'); 
} 
//--> 
</script>
</head>
<body>
    <a href="#" onclick="hello_world(this); return false;">Hello World!</a>

I keep getting the error saying that the object has no method setStyle. I thought FBJS was supposed to be part of facebook. Do I have to include fbjs in my canvas url?

Oh, and here's the url: http://apps.facebook.com/thedivide/

2

There are 2 answers

0
Mika Tuupola On BEST ANSWER

Your canvas app is in iframe mode. This means you can and should use normal JavaScript. If you want to use FBJS change your application to FBML mode. You can do this from you application setting in the Facebook Integration section. See the attached screenshot:

FBML mode

2
Please treat your mods well. On

Go to the sandbox and it should work.