Oct 7, 2008 at 9:08 PM
Edited Oct 7, 2008 at 9:22 PM
I know Facebook is supposed to support a restricted version of Javascript.  I have an FBML application but I have been, to this point, unable to get ANY javascript to work.

I've tried scripts as simple as: <a href="#" onclick="alert('hello world');">Click Me</a>

I've also tried both examples located here:

What is happening is Facebook appends my application id to all functions & variables.  Maybe that means I can't call a function that accesses the current document or window.

This is what I'm writing:

and this is the javascript that facebook renders:

How can I do a javascript alert?
Oct 7, 2008 at 9:35 PM
Facebook has their own flavour of Javascript... FBJS.  Check it out in the FB Wiki (never used it myself).
Oct 7, 2008 at 10:28 PM
FBJS doesnt allow alerts. Guess it could seen as annoying.

Try using dialogs,
Oct 7, 2008 at 11:02 PM
Thanks, what I was hoping to do is a popup window... do you know facebook allows that?
Oct 8, 2008 at 1:50 AM
To add to this discussion... I've been using the ASP.NET form validators.  I mostly use firefox but I was doing browser testing in IE7 today and noticed script errors caused by the .net validators.  In both browser the validators "work" but in IE7 I get an ugly script error alert message -- when loading the page and when submitting the form.

Any ideas or should I just abandon .net validators?
Oct 16, 2008 at 8:43 PM
Edited Oct 16, 2008 at 8:49 PM
Does anyone know how to successfully reference an element using FBJS?  What I want to do is

I may have just found the answer to my own question.  It appears you must use fbGetEl and fbCreateEl instead of document.getElementById and document.createElement. In the version of your page that is intended to be run inside of Facebook, include this code:
function fbGetEl(elId) {
return document.getElementById(elId);
function fbCreateEl(elType) {
return document.createElement(elType);

Alternatively, if you are feeling a little tricky, you can add in some code like this to the end of fbHelper.js

document.getElementById = fbGetEl;
document.createElement = fbGetEl;

I will give this a try and confirm this does work.
Oct 28, 2008 at 1:46 AM
Edited Oct 28, 2008 at 4:41 PM
The part I seemed to be missing is that FBJS requires you to use different Methods.  You still do a document.getElementById call as you would in JavaScript.