Window.Close() not working on Firefox

Last post 05-22-2008 6:16 AM by blodfox777. 6 replies.

Sort Posts:

  • Window.Close() not working on Firefox

    05-21-2008, 4:18 PM
    • Loading...
    • diadem_2k
    • Joined on 12-11-2006, 6:04 PM
    • Posts 284

    I have a case where if users clicks logout link, he will be directed to logout.aspx page and in the page_load of logout.aspx page.....i have added this code:

    This below pasted code works fine on IE6 and IE7 but not in firefox....i did search on google and tried all the ways that i found like adding:

    // Scripts & Windows prefs
    pref("dom.allow_scripts_to_close_windows", true);

    but nothing seams to be working for firefox??? is there any work around to fix this issue so that it works on IE and Firefox as well????

    thanks a lot in advance............ 

    ==================================================================================

     // Build A JavaScript String That Will Close This Web Browser Window
            StringBuilder jsScript = new StringBuilder();
            jsScript.Append("<script language='javascript' type='text/javascript'>");
            jsScript.Append("window.close();");
            jsScript.Append("</script>");

            //Add The JavaScript To The HTML Stream
            Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "CloseBrowser", jsScript.ToString());

     ==================================================================================

  • Re: Window.Close() not working on Firefox

    05-21-2008, 5:12 PM
    • Loading...
    • joshj
    • Joined on 05-17-2007, 9:37 PM
    • Posts 352

    From the mozilla developer's site:

    This method (window.close) is only allowed to be called for windows that were opened by a script using the window.open method...

    http://developer.mozilla.org/en/docs/DOM:window.close

     

    "I hear there’s rumors on the...uh...internets"
    - George W. Bush
  • Re: Window.Close() not working on Firefox

    05-21-2008, 11:40 PM
    Answer

    Hi

    use the following code instead of "window.close();"

    function winClose(){ window.top.opener = null; window.close(); }

    or

    function   closeWindow()   {    window.open('','_parent','');   window.close(); }

    if it doesn't works

    please set your firefox browser:

    1.input "about:config " to your firefox address bar and enter;

    2.make sure your "dom.allow_scripts_to_close_windows" is true

    Hope this helps!

    Regards!
    Lance
    -- "Mark As Answer" If my reply helped you --
  • Re: Window.Close() not working on Firefox

    05-22-2008, 1:42 AM
    • Loading...
    • jagan.unique
    • Joined on 02-08-2008, 9:42 AM
    • Hyderabad, India
    • Posts 232

    Hi

    try this. its working on both IE and FF

    <head runat="server">
        <title>Untitled Page</title>
      <script language="javascript">
     
       function openwin (url) {
           newwindow = window.open( url ,'openwin')
        }

       </script>

    </head>
    <body>
    <form runat="server" id="form1">
    <a href="javascript:openwin('default.aspx')">new window</a><br/>

        <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="window.newwindow.close();" />
    </form>
    </body>
    </html>

     

    Click “Mark as Answer” on the post(s) that helped you.
  • Re: Window.Close() not working on Firefox

    05-22-2008, 5:40 AM
    • Loading...
    • diadem_2k
    • Joined on 12-11-2006, 6:04 PM
    • Posts 284

     blodfox777,

    i tried the solution which you have posted but it didn't work....when i set the browser settings to true (dom..allow etc... to true)

    then it worked but wondering how to let users know about this....it would be nice if we have server side solution.......

    jagan...i will try your method and get back to you.... 

     

  • Re: Window.Close() not working on Firefox

    05-22-2008, 6:08 AM
    • Loading...
    • feroze1
    • Joined on 03-30-2007, 1:42 PM
    • Lahore
    • Posts 42
    use tihs 
    <a href="javascript:window.close();">Close This Window</a>
    Please "Mark As Answer" if helpfull..
    Feroze Ahmed
  • Re: Window.Close() not working on Firefox

    05-22-2008, 6:16 AM

    feroze1:
    use tihs 
    <a href="javascript:window.close();">Close This Window</a>

    I'm sorry but it can not be done if the window was not open by "window.open()" function

     

    Regards!
    Lance
    -- "Mark As Answer" If my reply helped you --
Page 1 of 1 (7 items)