I want to use javascript in my facebook application, but I don't know how to start with FBJS to use it. Someone help me please! just something like
<div onclick="greeting();">click me</div>
<script>
function greeting(){
alert("hello world");
}
</script>
I want to use javascript in my facebook application, but I don't know how to start with FBJS to use it. Someone help me please! just something like
<div onclick="greeting();">click me</div>
<script>
function greeting(){
alert("hello world");
}
</script>
Share
Improve this question
edited Jun 26, 2009 at 5:25
Kevin Montrose
22.7k9 gold badges93 silver badges140 bronze badges
asked Jun 26, 2009 at 3:41
gacongacon
2,1354 gold badges21 silver badges32 bronze badges
5
- Just so you're aware, FBJS can be quite restrictive. alert() does not work in FBJS. I found that extremely frustrating when first working with it. – zombat Commented Jun 26, 2009 at 4:59
- but when I create a function firebug always said: my function is not defined. Facebook automatic added numeric key to my function name and everything. Like this: 1234566_greeting is not defined. I don't know how to write an executable function in facebook application – gacon Commented Jun 26, 2009 at 8:48
- the reason for the numeric prefix is FB parses your stuff and pre-pends your application id to all javascript entities to prevent collisions. See my post below for an example of displaying a dialog box on a facebook page. – Mike Heinz Commented Jun 26, 2009 at 17:19
- Facebook will add that prefix to your functions (it's your app id) but they also add the prefix to any place in the document you reference the function name, so there shouldn't be any issue with being unable to reference the function. – defines Commented Jun 28, 2009 at 12:38
- Thank you for all of your help! I relize that I do not write script tag instead of I write script and type="text/javascript" so I fall in an non stoppable loop when I write in syntax javascript is not defined and of course I write it in FBJS with the same result. I hope to write out my mistake could help someone newbie like me! Thank you again all of you! – gacon Commented Jul 6, 2009 at 9:41
3 Answers
Reset to default 3This works for me:
<script type="text/javascript">
function areyousure(description,id,opt) { var dialog = new Dialog(Dialog.DIALOG_POP).showChoice('Are you sure?','Are you sure you want to delete "' + description + '"? This action cannot be undone!','Yes','No');
dialog.onconfirm = function() {
document.setLocation("http://apps.facebook./myapp/delete.php?rec
ord=" + id + opt);
}
}
</script>
.
.
.
<a href="#" onclick="areyousure(arg1,arg2,arg3)" ><img src="http://mysite/images/delete.png" /></a>
A quick list of things that will get you, and what you should use instead:
alert() -> no equivalent
new Array() -> []
new Object() -> {}
The "Big 2" DOM changes, that broke a lot of my code "back when":
innerHTML -> setInnerXHTML(), note that this is strict
id -> getId()
A list of all the DOM changes.
Beware that FBJS is pretty poorly documented, so you'll have to play around with some things to get everything working.
As per this handy blog post, you can use Facebook’s Dialog
object instead of alert
:
new Dialog().showMessage('Dialog', 'This is text');
http://thinkclay./technology/getting-started-with-facebook-js-fbjs
So you could rewrite your example code like this:
<div onclick="greeting();">click me</div>
<script>
function greeting(){
new Dialog().showMessage('Dialog', "hello world");
}
</script>
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744375106a4571147.html
评论列表(0条)