<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Facebook Cookbook &#187; Canvas</title>
	<atom:link href="http://fbcookbook.ofhas.in/tag/canvas/feed/" rel="self" type="application/rss+xml" />
	<link>http://fbcookbook.ofhas.in</link>
	<description>thousands of app development recipes</description>
	<lastBuildDate>Sun, 21 Mar 2010 10:38:11 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>how to  trigger multiple onload functions when divs  are  loaded by FBJS</title>
		<link>http://fbcookbook.ofhas.in/2009/02/15/how-to-trigger-multiple-onload-functions-when-divs-are-loaded-by-fbjs/</link>
		<comments>http://fbcookbook.ofhas.in/2009/02/15/how-to-trigger-multiple-onload-functions-when-divs-are-loaded-by-fbjs/#comments</comments>
		<pubDate>Sun, 15 Feb 2009 16:56:12 +0000</pubDate>
		<dc:creator>Saidur Rahman</dc:creator>
				<category><![CDATA[Application]]></category>
		<category><![CDATA[Canvas]]></category>
		<category><![CDATA[FBJS]]></category>

		<guid isPermaLink="false">http://fbcookbook.ofhas.in/?p=275</guid>
		<description><![CDATA[<div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;"><script type="text/javascript">
<!--
digg_url = 'http://fbcookbook.ofhas.in/2009/02/15/how-to-trigger-multiple-onload-functions-when-divs-are-loaded-by-fbjs/';
digg_bgcolor = '#FFFFFF';
digg_skin = '';
digg_window = '';
digg_title = 'how to  trigger multiple onload functions when divs  are  loaded by FBJS';
digg_bodytext = '';
digg_media = 'news';
digg_topic = '';
//-->
</script>
<script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script>
</div>




  
facing trouble to trigger multiple onload event to work  FBJS does not allow acess to the window object. So how can onload event fire when &#60;div&#62; is loaded on canvas. also FBJS is executed after the entire page has been loaded. so really shouldn&#8217;t matter where you call the function within your [...]]]></description>
			<content:encoded><![CDATA[<div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;"><script type="text/javascript">
<!--
digg_url = 'http://fbcookbook.ofhas.in/2009/02/15/how-to-trigger-multiple-onload-functions-when-divs-are-loaded-by-fbjs/';
digg_bgcolor = '#FFFFFF';
digg_skin = '';
digg_window = '';
digg_title = 'how to  trigger multiple onload functions when divs  are  loaded by FBJS';
digg_bodytext = '';
digg_media = 'news';
digg_topic = '';
//-->
</script>
<script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script>
</div>
<p><script type="text/javascript"><!--
google_ad_client = "pub-3649773907774827";
/* 468x15, created 9/26/09 */
google_ad_slot = "6695465500";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script><br />
<!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:PunctuationKerning /> <w:ValidateAgainstSchemas /> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:Compatibility> <w:BreakWrappedTables /> <w:SnapToGridInCell /> <w:WrapTextWithPunct /> <w:UseAsianBreakRules /> <w:DontGrowAutofit /> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles> </xml><![endif]--><!--[if !mso]><span class="mceItemObject"   classid="clsid:38481807-CA0E-42D2-BF39-B33AF135CC4D" id=ieooui></span> <mce:style><!  st1\:*{behavior:url(#ieooui) } --> <!--[endif]--><!--  /* Style Definitions */  p.MsoNormal, li.MsoNormal, div.MsoNormal 	{mso-style-parent:""; 	margin:0in; 	margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:12.0pt; 	font-family:"Times New Roman"; 	mso-fareast-font-family:"Times New Roman"; 	mso-bidi-font-family:"Times New Roman"; 	mso-bidi-language:AR-SA;} @page Section1 	{size:8.5in 11.0in; 	margin:1.0in 1.25in 1.0in 1.25in; 	mso-header-margin:.5in; 	mso-footer-margin:.5in; 	mso-paper-source:0;} div.Section1 	{page:Section1;} --><!--[if gte mso 10]> <mce:style><!   /* Style Definitions */  table.MsoNormalTable 	{mso-style-name:"Table Normal"; 	mso-tstyle-rowband-size:0; 	mso-tstyle-colband-size:0; 	mso-style-noshow:yes; 	mso-style-parent:""; 	mso-padding-alt:0in 5.4pt 0in 5.4pt; 	mso-para-margin:0in; 	mso-para-margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:10.0pt; 	font-family:"Times New Roman"; 	mso-ansi-language:#0400; 	mso-fareast-language:#0400; 	mso-bidi-language:#0400;} --> <!--[endif]--></p>
<p class="MsoNormal">facing trouble to trigger multiple onload event to work <span> </span>FBJS does not allow acess to the window object. So how can onload event fire when &lt;div&gt;<span> </span>is loaded on canvas. also FBJS is executed after the entire page has been loaded. so really shouldn&#8217;t matter where you call the function within your canvas page file. however let’s see how can we trigger on load for multiple div.</p>
<p class="MsoNormal">
<p class="MsoNormal">In this example we create two div which load by onload. One &lt;div=’msg’&gt; is for content a message and another &lt;div=’ ajax’&gt; which load the value by ajax way.</p>
<p class="MsoNormal">
<p class="MsoNormal"><span> </span>For that reason in FBJS we create a varraible <span> </span>array and pushing <span> </span>two functions on that array variable.</p>
<pre name="code" class="php">

var onload = [];

onload.push(function() {
//ONLOAD STUFFS HERE
msg_laod();
do_ajax();

});

&lt;/script&gt;
</pre>
<p class="MsoNormal">now we define the two functions. The message load function just simply display a text message on &lt;div id=’msg’&gt;. and do_ajax() function display the value by ajax call.</p>
<p class="MsoNormal">
<pre name="code" class="php">

&lt;script&gt;
function msg_laod()
{
document.getElementById(&#039;msg&#039;).setInnerHTML(&#039;test message content&#039;);

}

function do_ajax()
{
var ajax = new Ajax();
ajax.ondone = function(data) {
document.getElementById(&#039;req&#039;).setInnerFBML(data);
}
ajax.requireLogin = 1;
ajax.responseType = Ajax.FBML;
ajax.post(&#039;http://www.techsmashing.com/banglakeyboard/adduser.php&#039;);
}            ajax.post(.....display.php&#039;); // ajax callback url
}&lt;/script&gt;
</pre>
<p class="MsoNormal">
<p class="MsoNormal">now we trigger on the onload event . by pushing functions into an array and executing them at the bottom of the page it ensures that the elements are indeed in the dom tree.  here we add setTimeout function to to make sure the browser is fully loaded. It allows 100 miliseconds. because the rest of the page to load (facebook footer and such).   increasing the 100 milisecond limit can solve some of these problems.</p>
<p class="MsoNormal">
<p class="MsoNormal">
<pre name="code" class="php">
&lt;/p&gt;&lt;/p&gt;

&lt;script&gt;
//the very last thing on the page
setTimeout (function() {
for(var a = 0;a &lt; onload.length;a++) {onload[a]();}
}, 100);
&lt;/script&gt;
</pre>
<p class="MsoNormal">
<p class="MsoNormal">in this way we can easily load onload functions in the div. we combine the whole code and looks like that:</p>
<pre name="code" class="php">

&lt;?php
include_once &#039;config.php&#039;;
?&gt;
&lt;script&gt;
var onload = [];
onload.push(function() {
//ONLOAD STUFFS HERE
msg_laod();
do_ajax();

});

function msg_laod()
{
document.getElementById(&#039;msg&#039;).setInnerHTML(&#039;test message content&#039;);

}

function do_ajax()
{
var ajax = new Ajax();
ajax.ondone = function(data) {
document.getElementById(&#039;req&#039;).setInnerFBML(data);
}
ajax.requireLogin = 1;
ajax.responseType = Ajax.FBML;
ajax.post(&#039;ajax callback url&#039;);
}

&lt;/script&gt;
&lt;div id=&quot;msg&quot; style=&quot;width:398px;height:298px;&quot;&gt;test message content&lt;/div&gt;
&lt;div id=&quot;ajax&quot; style=&quot;width: 398px; height: 298px;&quot;&gt; &lt;/div&gt;

&lt;script&gt;
//the very last thing on the page
setTimeout(function() {
for(var a = 0;a &lt; onload.length;a++) {onload[a]();}
}, 100);
&lt;/script&gt;
</pre>
<p><strong>reference</strong> :</p>
<p><a href="http://forum.developers.facebook.com/viewtopic.php?id=5117">http://forum.developers.facebook.com/viewtopic.php?id=5117</a><br />
<script type="text/javascript"><!--
google_ad_client = "pub-3649773907774827";
/* 468x15, created 9/26/09 */
google_ad_slot = "6695465500";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
]]></content:encoded>
			<wfw:commentRss>http://fbcookbook.ofhas.in/2009/02/15/how-to-trigger-multiple-onload-functions-when-divs-are-loaded-by-fbjs/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>
