JavaScript in FBML

Facebook provides an FBML-specific version of JavaScript parsing called FBJS (Facebook JavaScript). This helps protect and not confuse the external scripts Facebook uses on the rest of its site. (We’ll cover FBJS in much more detail in Chapter 4.) Facebook wants to maintain security on profile pages so that users don’t get inundated with music, videos, and pop ups right when they visit a profile page.

Similar to <link/> tags in CSS, you can load external JavaScript files through <script/> tags that get cached in exactly the same way as <link/> tags. For example, to load external JavaScript, you would load a <script/> tag such as the following:

<script src="http://fbmlessentials.staynalive.com/facebook.js?version=
    1.0"></script>

Calls to the <script/> tag are limited to canvas pages only. Profile boxes can use FBJS, but they must be called with inline JavaScript rather than by an external JavaScript file.

Here are some rules regarding FBJS:

  • Methods are prepended with app, followed by the application ID of your app and an underscore. Be sure when referencing the method later to reference the parsed method name instead of your original method name. Global functions provided by Facebook are not rewritten in this manner.

  • Only the onclick attribute is supported in FBML/HTML elements for your app. To access other events for your FBML/HTML, you must set up an event listener.

  • Profile FBJS only activates after a user performs some sort of click action in the application’s profile box. This prevents music, pop ups, and other things happening without the user’s permission when visiting another user’s profile page.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.139.8