Page view counter

Want to close the main window and popup window

Last post 09-16-2008 3:04 AM by nevincm. 16 replies.

Sort Posts:

  • Want to close the main window and popup window

    08-29-2008, 10:16 AM
    • Loading...
    • nevincm
    • Joined on 07-10-2007, 7:05 AM
    • Posts 41

     hi all,

    Thanks for all the support and help . Right now i am facing a problem.

    I have a main page with six frames and each frame is loaded with same page having a farpoint spread with different data .

    All spread has hyperlinks and when it is clicked , it will pop up a popup window . 

    The problem is with session expiry .

    The popup also have spreads with hyperlink s . When some one clicks the hyperlink it will popup one more link .

    Each page load i am checking session is null or not and session timeout is 30 

    When the third popup checks and find that session variable is empty .

    The code below will  execute 

     

            If Session("User_Id") = "" Then
                strMsg = "<script language='javascript'>openWindowMsg('" & "Msg.aspx?MSG=User session has expired!" & "');</script>"
                ClientScript.RegisterStartupScript(GetType(String), "strMsg", strMsg)
                Exit Sub
            End If

     

    function openWindowMsg(page)
    {
     
        var op = window.opener;
        op.opener = self;
        op.close();      
        window.open(page);
       
        self.opener = this;
        self.close();
     }

     

     

    So what my intention is to open the new page showing a message that the " User session has expired" and in that page there is one more hyperlink

    when got clicked launches the login page 

    But what is happening is the the mainpage is still there and message page has come .when i click on the link  in Msg page it will redirect to login page. But at the same time Main page is still there

    What was  my plan when session got expired and on the call of the javascript function "openWindowMsg"  all the windows including the main page has to be closed and messagepage.aspx is the only window that should be there .

     

    How can i close those windows 

     

    Please help me 

     

    thanks & regards 

     nevviin

     

  • Re: Want to close the main window and popup window

    08-30-2008, 8:28 AM
    • Loading...
    • NC01
    • Joined on 08-26-2005, 3:33 PM
    • Posts 10,503
    • TrustedFriends-MVPs

    Try this. Add to Msg.aspx

    <script type="text/javascript">
    <!--
    function closeWindow()
    {
     window.opener.open('', '_parent');
     window.opener.close();

     // Rest of code...
    }
    // -->
    </script>

    You might have a problem in that a confirmation dialog might appear to confirm closing the parent window by the user, but there is nothing that you can do about that.

    NC...

  • Re: tried, it's not working ? any other options?

    09-01-2008, 3:49 AM
    • Loading...
    • nevincm
    • Joined on 07-10-2007, 7:05 AM
    • Posts 41

    hi ,

    thanks for reading and replying 

     

    I tried  but it's not working .

    The main page i am  opening using the response.redirect.

    "  Response.Redirect("Main.aspx")  "

    Rest of the popups are opened by  javascript open method

     

    thanks & regards 

     

     

     

     

     

     

     

     

     

  • Re: tried, it's not working ? any other options?

    09-01-2008, 8:13 AM
    Answer
    • Loading...
    • NC01
    • Joined on 08-26-2005, 3:33 PM
    • Posts 10,503
    • TrustedFriends-MVPs

    I don't understand what you are trying to do but, you can only close windows from a parent window (a window that opened the other windows), by storing a reference to each window, and using that reference to close them.

    <script type="text/javascript">
    <!--
    var windowRef = null;
    function openWindow(windowUrl)
    {
     windowRef = window.open(windowUrl, ...
    }

    function closeWindow()
    {
     if ( (windowRef) && (windowRef.closed == false) )
      windowRef.close();

     windowRef = null;
    }
    // -->
    </script>

    Even that will not work if a PostBack occurs on the parent because the window reference will be lost.

    Security is supposed to prevent you from closing the parent window, because in theory, you should only be able to close windows that were opened by some user action such as a button press. This still works in some browsers however:

    From the parent window:
    <script type="text/javascript">
    <!--
    function closeParentWindow()
    {
     window.open('', '_parent');
     window.close();
    }
    // -->
    </script>

    From a child window:
    <script type="text/javascript">
    <!--
    function closeParentWindow()
    {
     window.opener.open('', '_parent');
     window.opener.close();
    }
    // -->
    </script>

    Oh, and if you use Response.Redirect, you cannot close the old window since the new window has no window.opener property.

    NC...

     

  • Re: Want to close the main window and popup window

    09-01-2008, 8:30 AM

    Hi,

    Here a small example, try it out. This will close the parent window and open a new one... function test() { window.opener = top; window.close(); window.open("d:\\1.html", "", "fullscreen=yes"); }  

    <html>
    <head>
    <script language="javascript">
    function test()
    {
     window.opener = top;
     window.close();
     window.open("d:\\1.html", "self", "fullscreen=yes");
    }
    </script>
    </head>
    <body>
    <input type=button onclick="test();" value="b">
    </body>
    </html>



    Please remember to click “Mark as Answer” on the post that helps you.
  • Re: Want to close the main window and popup window

    09-01-2008, 8:39 AM
    • Loading...
    • NC01
    • Joined on 08-26-2005, 3:33 PM
    • Posts 10,503
    • TrustedFriends-MVPs

    Sorry suthish nair, but window.open("d:\\1.html", "self", "fullscreen=yes"); will NOT work. You will get an access denied error.

    NC...

  • Re: Want to close the main window and popup window

    09-01-2008, 8:43 AM

    Hi NCO1,

    I just shown an example, how to close parent window and open a new one. In my case its working fine.

    Thanks



    Please remember to click “Mark as Answer” on the post that helps you.
  • Re: Want to close the main window and popup window

    09-01-2008, 8:53 AM
    • Loading...
    • NC01
    • Joined on 08-26-2005, 3:33 PM
    • Posts 10,503
    • TrustedFriends-MVPs

    Well it might work with an HTML page, but this is an ASP.NET forum and
    function test()
    {
     window.opener = top;
     window.close();
     window.open("d:\\1.aspx", "self", "fullscreen=yes");
    }

    1. Produces an "Access denied" error
    2. Produces a user confirmation message to popup that something is trying to close the browser window.

    NC...

  • Re: Want to close the main window and popup window

    09-01-2008, 9:24 AM

     

    Ok, Your are talking about file path. Use location.href instead of file path.

    window.open(location.href, "self", "fullscreen=yes");

    Also, all asp.net pages contains html tags :-)



    Please remember to click “Mark as Answer” on the post that helps you.
  • Re: Want to close the main window and popup window

    09-01-2008, 9:36 AM
    • Loading...
    • NC01
    • Joined on 08-26-2005, 3:33 PM
    • Posts 10,503
    • TrustedFriends-MVPs

    Yes, that would work, but you will still get the user confirmation message, which the post was all about to start with.

    NC...

     

  • Re: Want to close the main window and popup window

    09-01-2008, 10:46 AM

     

    ok, but working for me..

    check this forum: http://forums.asp.net/t/1313518.aspx ==> got solution for inbaa



    Please remember to click “Mark as Answer” on the post that helps you.
  • Re: Want to close the main window and popup window

    09-02-2008, 7:55 AM
    • Loading...
    • NC01
    • Joined on 08-26-2005, 3:33 PM
    • Posts 10,503
    • TrustedFriends-MVPs

    Yeah, you said that in the other post, but it doesn't work for anyone BUT you. What browser and version are you using? I KNOW that it does not work in IE 7 or Firefox 2.0 and up.

    NC...

  • Re: Want to close the main window and popup window

    09-02-2008, 8:04 AM
    Ok, might be version issue. Am using IE6.


    Please remember to click “Mark as Answer” on the post that helps you.
  • Re: Want to close the main window and popup window

    09-02-2008, 8:08 AM
    Answer
    • Loading...
    • NC01
    • Joined on 08-26-2005, 3:33 PM
    • Posts 10,503
    • TrustedFriends-MVPs

    There ya go! You should post that on the other thread. And you can try this to take it's place for IE 7 (not Firefox), but I believe that they've even stopped that from working in IE 8 beta.

    <script type="text/javascript">
    <!--
    function closeWindow()
    {
        window.open('', '_parent');
        window.close();
    }
    // -->
    </script>

    NC...

     

  • Big Smile [:D] Re: Want to close the main window and popup window

    09-02-2008, 8:18 AM

     

    Smile tanx NC, for helping me also.



    Please remember to click “Mark as Answer” on the post that helps you.
Page 1 of 2 (17 items) 1 2 Next >