tags:

views:

6501

answers:

2

I want to hover the image in static FBML page.

But even the following simple code doesn't work:

<div id="button1">button1</div>
<div id="button2" onmouseover="document.getElementById('button1').setStyle({display: 'none'})">button2</div>


<script type="text/javascript">
    document.getElementById('button1').setStyle({display: 'none'});
</script>

When "onmouseover" changes to "onclick", it works.

<div id="button1">button1</div>
<div id="button2" onclick="document.getElementById('button1').setStyle({display: 'none'})">button2</div>


<script type="text/javascript">
    document.getElementById('button1').setStyle({display: 'none'});
</script>

Is there anything wrong?

A: 

Javascript is not allowed in facebook FBML applications (they may be allowed in IFrame applications but im not certain). See http://wiki.developers.facebook.com/index.php/FBJS for the alternative, Facebook JS.

EDIT: In this case it will not work as javascript placed in profile boxes is not executed until the first user event. From the FBJS wiki:

"In profile boxes, inline scripts are deferred until the first "active" event is triggered by a user. An active event is considered either onfocus, onclick, onmousedown, and so forth. Basically anything that requires a mouse click is an "active" event. On a canvas page, however, this example works just fine."

WiseGuyEh
My example code is FBJS already.
Billy
the wiki page mentions that code should be setup like this:<script><!--//--></script>try inserting your FBJS within these script tags like so:<script><!--document.getElementById('button1').setStyle({display: 'none'});//--></script>
WiseGuyEh
please note there should be line breaks after each comment and the script tags - see http://wiki.developers.facebook.com/index.php/FBJS#The_Basics and look at the "best practice" part
WiseGuyEh
Addition information is added.
Billy
is this for a profile box? if so, the wiki mentions that javascript will only be executed after the user executes an event such as onclick.
WiseGuyEh
WiseGuyEh, where do you find this information?
Billy
"In profile boxes, inline scripts are deferred until the first "active" event is triggered by a user. An active event is considered either onfocus, onclick, onmousedown, and so forth. Basically anything that requires a mouse click is an "active" event. On a canvas page, however, this example works just fine."under "The Basics" section of the wiki
WiseGuyEh
Thank you.I can tell the client that it cannot be done.
Billy
A: 

did anyone find a solution for this? Im calling a function from flash with fbjs bridge and need something to initiate the inline scripts.

Breakmachine

related questions