Facebook Javascript API SDK and Init method -
i use start sdk of api js of facebook :
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>documento sin tÃtulo</title> </head> <body> <script type="text/javascript"> window.fbasyncinit = function() { fb.init({ appid:'<?php echo $appf['id'];?>', channelurl:'<?php echo $appf['url'];?>', status:true, cookie:true, xfbml:true }); function test() { alert("okokok"); } } </script> <script> (function() { var e = document.createelement('script'); e.type = 'text/javascript'; e.src = document.location.protocol + '//connect.facebook.net/en_us/all.js'; e.async = true; document.getelementbyid('fb-root').appendchild(e); }()); </script> <a href="#" onclick="test()">active alert test</a> </body> </html>
my problem it´s need insert functions login of facebook , if put code inside of fb.init , never works in example , functions works outside of fb.init
i don´t understand why happend because functions example :
fb.getloginstatus(function(response)
works inside fb.init
i understand did bad getting errors because have little function login , inside of fb.init no works
scoping, syntax , teh rulez
test()
illegitimate child of fbasyncinit()
child of window.
if idea alert
when clicking element - if fbasyncinit()
initialised - you'd better off testing property...
window.foo = function() { var bar = "baz"; }; window.test = function() { if ( typeof foo === "function" ) { alert( "whoot!" ); } else { var oh_nose = true; } }
...or similar.
then call test()
- child of window
- when clicky element gets poked.
notice that:
calling alert()
- child of window
- works same way. can argued (and is) correct way call alert()
calling window.alert( "whatever" );
.
an aside
consider using html5 via <!doctype html>
see
an answer on question more details.
Comments
Post a Comment