在IE浏览器中,Oauth登录弹窗无法关闭

3

我已经为Google OAuth编写了JavaScript代码以实现OAuth登录弹出窗口,代码如下:

    function authorize(authorize_url,get_token,get_token_secret)
    {
        console.log("acToken is "+get_token);

    var win         =   window.open(authorize_url, "windowname2", "width=800, height=600"); 

   var pollTimer   =   window.setInterval(function() { 
       try
       {
       if (win.document.URL.indexOf(oauth_callback) != -1) {
           console.log("url inside callback"+win.document.URL)
           window.clearInterval(pollTimer);

           win.close();

           getting_access_token(get_token,get_token_secret);
       }
       }catch(e)
       {

       }
   },100);
}

在打开Oauth的窗口中,但是在点击允许后,它没有进入window.setinterval函数的if语句,这就是为什么弹出窗口在IE中无法关闭,而在Firefox和Chrome中窗口可以正常关闭的原因。如何解决这个问题在IE中。

1个回答

0

您应该在新窗口中打开登录页面,然后重定向到成功页面,最后关闭弹出窗口:

page.html

function login() {
    var win = window.open('', 'login.html', 'width=800,height=400');
    win.focus();
}

login.html

window.location.href = 'success.html'; // or use server-side redirect

success.html

window.opener.close();

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接