如何关闭弹出窗口并重定向父窗口

问题描述 投票:10回答:3
string dialog_url = "http://www.facebook.com/dialog/oauth?client_id=" + app_id + "&redirect_uri=" + Server.UrlEncode(my_url) + "&scope=" + permission;
ClientScript.RegisterClientScriptBlock(typeof(Page), "key", "window.open('"+dialog_url+"','_parent','');");

我将此代码用于弹出权限对话框。当用户单击允许Facebook将用户重定向到弹出窗口中的我的应用程序时。我需要将代码从弹出窗口发送到父窗口,然后在用户单击允许时关闭弹出窗口。

javascript facebook popupwindow
3个回答
18
投票

告诉我,如果这是您想要的...父窗口:

<html>
<head>

    <script language="Javascript">

        function showFBWindow(){
            url = "allowfbchild.html"
            newwindow=window.open(url,'name','height=200,width=150');
            if (window.focus) {newwindow.focus()}
        }

    </script>

</head>
<body>

    <input type="button" OnClick="showFBWindow()" value="Open FB" />

</body>
</html>

子窗口(allowfbchild.html):

<html>
<head>

    <script language="Javascript">

        function redirectToFB(){
            window.opener.location.href="http://wwww.facebook.com";
            self.close();
        }

    </script>

</head>
<body>

    Allow the user to view FB
    <br/>Are you sure?
    <input type="button" value="Ok" OnClick="redirectToFB()" />

</body>
</html>

0
投票

在父页面中,按如下所示编写javascript

 <script language="Javascript">
     function popitup(url)
     {
      newwindow = window.open(url, "popwin", "width = 320, height = 210,  resizable = no");
      if (window.focus) { newwindow.focus() }
      return false;
      popwin.moveTo(0, 0);
      }
</script>

<a href=""   onclick="return popitup('myapppopup.aspx');return false;">`myapppopup</a>`

然后在弹出窗口中添加如下指向Facebook的链接

<a href="http://wwww.facebook.com"   target="_blank"   onclick="self.close();">facebook </a>

0
投票

这是您的父窗口:

<script language="javascript">

    function open_a_window() 
    {
        var w = 200;
            var h = 200;
            var left = Number((screen.width/2)-(w/2));
            var tops = Number((screen.height/2)-(h/2));

            window.open("window_to_close.html", '', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+tops+', left='+left);

       return false;
    }

    </script>

    <input type="button" onclick="return open_a_window();" value="Open New Window/Tab" />

这是您的子窗口:

<!DOCTYPE html>
<html>
<body onload="quitBox('quit');">

<h1>The window closer:</h1>

<input type="button" onclick="return quitBox('quit');" value="Close This Window/Tab" /> 


<script language="javascript">

function quitBox(cmd) 
{      
    if (cmd=='quit')    
    {
       var url = 'https://www.google.com';
       window.opener.document.location.href = url;
       open(location, '_self').close();       
    }     
    return false;   
}

</script>

</body>
</html>
© www.soinside.com 2019 - 2024. All rights reserved.