define javascript functions on iframe facebook app inside <fb:serverfbml> tag

Posted by user233486 on Stack Overflow See other posts from Stack Overflow or by user233486
Published on 2009-12-17T14:43:36Z Indexed on 2010/04/10 7:03 UTC
Read the original article Hit count: 407

Hi all,

How we can define JS function on inside ? I tried to load file javascript on the end tag , but I still can't call the function from javascript file.

Here the FBML tag

<fb:serverfbml>
  <script type="text/fbml">
    <fb:fbml>
      <a href="#" id="this" onclick="do_colors(this); return false">Hello World!</a>
      <script src="http://absolute.path.to/your/javascript/file.js"></script>
    </fb:fbml>
  </script>
</fb:serverfbml>

And here the javacript function on file.js

function random_int(lo, hi) { 
    return Math.floor((Math.random() * (hi - lo)) + lo) 
} 

function do_colors(obj) { 
    var r = random_int(0, 255), b = random_int(0, 255), g = random_int(0, 255); 
    obj.setStyle({background: 'rgb('+[r, g, b].join(',')+')', 
    					color: 'rgb('+[r<128?r+128:r-128, g<128?g+128:g-128, b<128?b+128:b-128].join(',')+')'}); 
}

I use rails and facebooker to develop the application Any idea or suggestion for define javascript functions?

Thanks,

© Stack Overflow or respective owner

Related posts about ruby

Related posts about ruby-on-rails