FB.api响应回调异步弹出窗口被阻止 [英] FB.api response callback async popup blocked

查看:124
本文介绍了FB.api响应回调异步弹出窗口被阻止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

FB.api('/me', function(response) {
// this is async
//other logic goes here
window.open(mylink + response.name);
}

异步问题使我无法执行过程编程风格,因此我将代码放入了代码块中,但该代码被弹出窗口阻止程序阻止了.如何解决这个问题?我用谷歌搜索,人们说这可能使异步错误.

解决方案

您无法在异步回调函数中打开弹出窗口,必须始终在用户交互时直接打开它.这是一项重要的浏览器功能,可以保护用户免受不必要的弹出式窗口的攻击.<​​/p>

您一定要在用户单击之前调用FB.api.在初始化JavaScript SDK之后立即调用FB.api('/me')应该没有问题,并将其存储在变量中以备后用.

FB.api('/me', function(response) {
// this is async
//other logic goes here
window.open(mylink + response.name);
}

The async problem make me can't do procedure programming style, so I put my code within the block, it got blocked by popup blocker. How to resolve this issue? I googled and people said it can be make async false.

解决方案

You cannot open a popup in an asynchronous callback function, you always have to open it directly on user interaction. This is an important browser feature to protect the user from unwanted popups.

You definitely have to call FB.api BEFORE the user click. Should be no problem to call FB.api('/me') right after initializing the JavaScript SDK and store it in a variable for later.

这篇关于FB.api响应回调异步弹出窗口被阻止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆