如何使用Javascript动态地修改fb:request-form的内容?

问题描述:

我想使用javascript自定义我的请求表单内容。 说我在我的HTML有这样的...如何使用Javascript动态地修改fb:request-form的内容?

<div id="invite"> 
<fb:serverfbml style="width: 600px; height: 650px;"> 
    <script type="text/fbml"> 
     <fb:request-form 
      action="index.php" 
      method="POST" 
      invite="true" 
      type="MyApp" 
      content="Please have a look at my new __DYNAMICNAME_HERE__. 
       <fb:req-choice url='http://apps.facebook.com/myapp/' label='View Now!' />" > 

      <div class="clearfix" style="padding-bottom: 10px;"> 
       <fb:multi-friend-selector condensed="true" style="width: 600px;" /> 
      </div> 
      <fb:request-form-submit /></fb:request-form> 
    </script> 
</fb:serverfbml></div> 

我想动态改变_DYNAMICNAME_HERE_到通过JavaScript别的东西。

这是我试过的东西。

function technique1() 
{ 
    var elem = document.getElementById("invite"); 
    elem.innerHtml = elem.innerHTML.replace("__DYNAMICNAME_HERE__", "MyName"); 
    // show div code... 

    // result is, the current page get's re-rendered inside the div, instead of the FB controls. 
} 

function technique2() 
{ 
    // Delete all code inside the div... then construct the content using javascript. 

    var elem = document.getElementById("invite"); 
    elem.innerHtml = text;// text is the div innerHtml code constructed at runtime. 

    // run show div code 
    // result is nothing shows. 
} 

function technique3() 
{ 
    // First, we remove all code from the div 
    // put them into another php page called invite.php 

    var elem = document.getElementById("invite"); 
    elem.innerHtml = "<iFrame src=\"www.myserver.com/invite.php?name=myname\"></iFrame>"; 

    // run show div code 
    // It works but requires 1 more request to the server. 
} 

有谁知道一种技术,不涉及额外的请求到服务器(invite.php)?可能涉及FB.XFBML.Host.addElement,刷新等...

顺便说一句,我使用Google的Closure处理弹出div。

谢谢。

它实际上设计为现在允许这种操纵。你可以做的一件事是呈现多个fb:request-form,其中大部分在< div> s中,style =“display:none”,然后更改使用javascript显示哪一个。

这是一个有限的解决方案,因为它提供了有限的选择,必须在渲染时确定,但AFAIK在渲染后无法获取html属性。

我也遇到了同样的问题,并解决了teepark建议的方式。 我无法更改Facebook标签的HTML,因为它们在iframe中呈现。 我的页面位于www.____.com,iframe位于www.facebook.com。由于跨域策略,我无法更改该iframe中的内容。