我想使用 JavaScript 自定义我的请求表单内容。 假设我的 html 中有这个...
<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>
我想通过 Javascript 将 _DYNAMICNAME_HERE_ 动态更改为其他内容。
这是我尝试过的事情。
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 的句柄。
谢谢。
最佳答案
我也遇到了同样的问题,并按照teepark建议的方式解决了。 我无法更改 facebook 标签的 HTML,因为它们在 iframe 中呈现。 我的页面位于 www.____.com,iframe 位于 www.facebook.com。由于跨域策略,我无法更改该 iframe 中的内容。
关于javascript - 如何修改fb :request-form dynamically using Javascript?的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1988294/