简体   繁体   English

Facebook中的FBJS

[英]FBJS in facebook

I want to use javascript in my facebook application, but I don't know how to start with FBJS to use it. 我想在我的facebook应用程序中使用javascript,但我不知道如何从FBJS开始使用它。 Someone help me please! 有人帮帮我! just something like 就是这样的

<div onclick="greeting();">click me</div>
<script>
function greeting(){
  alert("hello world");
}
</script>

This 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.com/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": “Big 2”DOM发生了变化,这使我的代码“退回时”:

innerHTML -> setInnerXHTML(), note that this is strict  
id -> getId()  

A list of all the DOM changes . 所有DOM更改的列表

Beware that FBJS is pretty poorly documented, so you'll have to play around with some things to get everything working. 请注意FBJS记录很差,所以你必须玩一些东西才能让一切正常。

As per this handy blog post , you can use Facebook's Dialog object instead of alert : 根据这篇方便的博客文章 ,您可以使用Facebook的Dialog对象而不是alert

 new Dialog().showMessage('Dialog', 'This is text'); 

http://thinkclay.com/technology/getting-started-with-facebook-js-fbjs http://thinkclay.com/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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM