防止弹出窗口被阻止 [英] Prevent pop-ups from being blocked

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

问题描述

我正在页面加载的代码中使用Facebook登录方法,但是当我执行此代码时,弹出窗口拦截器关闭了Facebook权限窗口。

I am using a Facebook login method in my code on page load, but when I execute this code, the pop-up blocker closes the Facebook permission window.

如何使用 Javascript 打开此窗口,而不需要在弹出窗口拦截器中出现异常?

How can I open this window with Javascript without needing to make an exception in the pop-up blocker?

下面是我的代码:

FB.login(function(response)
{
    if(response.session!=null)
    {
        window.location.href='http://example.com';
    }
},
{ perms: 'email,user_birthday,publish_stream' });


推荐答案

你可以这样做 -

var uri = encodeURI('http://example.com');
FB.getLoginStatus(function(response) {
      if (response.status === 'connected') {
                window.location.href=uri;
      } else {
         window.location = encodeURI("https://www.facebook.com/dialog/oauth?client_id=YOUR_APP_ID&redirect_uri="+uri+"&response_type=token");
      }

这将直接重定向而不是打开弹出窗口

This will just redirect directly instead of opening a pop-up

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

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