动态更改 Facebook 发送按钮的 URL
我正在尝试使用 Javascript 动态更改 Facebook 发送按钮的 URL,但到目前为止还没有成功。
我设置了一个包含一些输入的页面,并且我希望发送按钮的 URL 在发送之前将字段值作为参数。问题是当我将发送按钮添加到页面时,它会在里面生成 iframe 代码,即使我稍后修改 href 参数,iframe 仍然保留原始链接。我想解决方案是刷新内容发送按钮以某种方式或在页面加载后添加它,一旦字段完成,但我无法弄清楚。
感谢您的帮助。
I am trying to dynamically change the URL of a Facebook Send button with Javascript, but I have had no success so far.
I have a page set up with a few inputs, and I would like the URL of the send button to take the fields value as parameters before it sends it. The problem is when I add the send button to the page, it generates the iframe code inside and even if I modify the href parameter later on, the iframe still keeps the original link in. I guess the solution would be to refresh the content of the send button somehow or add it after page load, once the fields have been completed, but I couldn't figure it out.
Thanks for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试使用 iFrame 版本的“点赞”按钮,而不是 XFBML 版本。提交表单后,可以通过 AJAX 调用将“赞”按钮后加载到页面中,在该调用中您已传递了表单中填写的数据。
You can try using the iFrame version of the like button instead the XFBML version. The like button can be post-loaded into the page after the form submission, via an AJAX call, in which you have passed the data filled up in the form.
你不能这样做。 Javascript 不能用于控制与您所在域不同的 iFrame。这是由于同源政策。
您可以做的是更改发送按钮 xfbml 标记上的参数,然后调用 FB.XFBML.parse(); 以便按钮使用新参数。
You can't do this. Javascript can't be used to control an iFrame on a different domain than yours. This is due to the Same Origin Policy.
What you can do is change the parameters on you send button xfbml tag and then call
FB.XFBML.parse();
so the button uses the new parameters.