How to close popup window and redirect the parent window

JBJumboJB picture JBJumboJB · Feb 19, 2011 · Viewed 75.6k times · Source
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','');");

I use this code for popup permission dialog. When user click allow facebook redirect user to my app in the popup. I need to send code from popup window to parent window then close popup when user click allow.

Answer

J K picture J K · Feb 19, 2011

Tell me if this is what you are looking for... Parent Window:

<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>

Child Window(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>