【问题标题】:Cross domain communication跨域通信
【发布时间】:2011-01-22 01:19:52
【问题描述】:

我正在开发一个 iframe facebook 应用程序。

在某个时候,我打开了一个 facebook 好友对话框,我在上面放了一个 html 按钮,这样我就可以添加一些特定于我的应用程序的逻辑。

dialog = FB.ui({
                method:'fbml.dialog', 
                fbml: (
                    '<fb:request-form  target="_self" action="http://devel.home.net/facebook/?cmd=fb_submit_form" ' +
                        'method="post" invite="false" type="event" ' +
                        'content="Would you like to attend the '+fb.EVENT.displayName+' event? &lt;fb:req-choice url=\'http://www.facebook.com/event.php?eid='+fb.EVENT.details.fb_event.id+'\' label=\'Respond now\' /&gt;" >' + 
                        emails.join('') +
                        '<input type="hidden" fb_protected="true" name="event" value="'+fb.RESPONSE.id+'"/>' +
                        '<fb:multi-friend-selector email_invite="false" import_external_friends="false" exclude_ids="'+appUsers+'"'+
                            'condensed="true" showborder="false" bypass="cancel" actiontext="Invite your friends to join" /> '+

                        '<br/><fb:request-form-submit import_external_friends="false"/>' +
                    '</fb:request-form>' + 

                    '<div style="padding:10px">You are also sending '+fb.EMAILS.length+' invitations via email</div>' + 
                    '<button id="email-button">Send Emails</button>'
                    ),
                    size: { width:640, height:480}, width:640, height:480
                });


            $('.fb_dialog_iframe').find('IFRAME').load(function(){
                $(this).contents().find('#email-button').click(function(){
                    alert(1)
                });
            })

基本上,Facebook 会为对话框创建一个 iframe

所以我将 onload 处理程序附加到 iframe 并尝试访问按钮

我收到权限被拒绝错误

Permission denied for <http://devel.home.net> (document.domain=<http://home.net>) to get property HTMLDocument.ownerDocument from <https://www.facebook.com> (document.domain=<https://facebook.com>).

有什么解决办法吗?

谢谢

【问题讨论】:

  • 谢谢大家的帮助

标签: javascript cross-domain


【解决方案1】:

您不能执行跨站点脚本 (http://en.wikipedia.org/wiki/Cross-site_scripting),尤其是针对 Facebook 等网络。

【讨论】:

    【解决方案2】:

    唯一可能的方法是使用闪光灯或银光物体。

    【讨论】:

      猜你喜欢
      • 2011-12-27
      • 1970-01-01
      • 2014-09-14
      • 1970-01-01
      • 2013-02-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多