Close parent window using JavaScript (Problem with Chrome and Firefox)

  1. #1

    Close parent window using JavaScript (Problem with Chrome and Firefox)

    Hello,

    I use this code to open and close a parent window:

    In my main page use this code:

    ASPX:
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MyMainPage.aspx.cs" Inherits="UserInterface.MyMainPage" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    
    
    <html  xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>Document title </title>
        
        
    </head>
    <body>
          
        <form id="form" runat="server">
        <ext:ScriptManager ID="ScriptManager1" runat="server" /> 
    		...
            <ext:ViewPort ID="ViewPort1" runat="server" >
            <Body>
                <ext:BorderLayout ID="BorderLayout1" runat="server">
                   <North>
                        <ext:Panel ID="PanelSearch" runat="server" Title="Title1" Frame="true"  Height="90" Collapsible="true" >
                            <Body>
                                 ...
                            </Body>
                       </ext:Panel>
                       </North>
                    <Center>
                        <ext:Panel ID="PanelGrid1" Title="Titlepg" runat="server" Frame="true" Icon="BookOpenMark" Collapsible="true" Header="false">
                            <Body>
                                ...
                            </Body>
                         </ext:Panel>
                    </Center>
                </ext:BorderLayout>
             </Body>
             </ext:ViewPort>
             
            <!-- [EXT. WINDOW] -->        <ext:Window ID="ExtWindowInsert" Title="Title2" runat="server" Icon="Add" Resizable="false" ShowOnLoad="false" />
               
            <ext:Button ID="btnHideExtWindowInsert" Hidden="true" runat="server">
                <Listeners>
                    <Click Handler="#{ExtWindowInsert}.hide()" />
                </Listeners>
                <AjaxEvents> 
                    <Click OnEvent="OnInsert"   />
                </AjaxEvents>
            </ext:Button>   
    
        </form>
    </body>
    </html>
    To call my external page, I use this C# code:
    private void LoadExtWindowInsert()
    {
    	this.ExtWindowInsert.Width = Unit.Pixel(320);
    	this.ExtWindowInsert.Height = Unit.Pixel(220);
    	this.ExtWindowInsert.Modal = false;
    	this.ExtWindowInsert.Collapsible = true;
    	this.ExtWindowInsert.Maximizable = true;
    	this.ExtWindowInsert.AutoLoad.Url = "MyExternalPage.aspx";
    	this.ExtWindowInsert.AutoLoad.Mode = LoadMode.IFrame;
    	this.ExtWindowInsert.AutoLoad.NoCache = true;
    	this.ExtWindowInsert.LoadContent();
    }
    Then if I execute this code:

    
    LoadExtWindowInsert();
    this.ExtWindowInsert.Show();
    I can show in my window an external page (window of my main page (parent page)).

    The code of the external page is the next:
    ASPX:

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MyExternalPage.aspx.cs" Inherits="UserInterface.MyExternalPage" %>
    
    <%@ Import Namespace="Coolite.Utilities" %>
    
    <%@ Register assembly="Coolite.Ext.Web" namespace="Coolite.Ext.Web" tagprefix="ext" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>Title</title>
        
    
    
        <script type="text/javascript">
    
            var updateParentWindow = function () {
                var buttonHiddenWindow = parent.document.getElementById('btnHideExtWindowInsert');
                if (buttonHiddenWindow != null) {
                    buttonHiddenWindow.click();
                }
            }
         </script>
    </head>
    <body>
        <form id="Form1" runat="server">
            <ext:ScriptManager ID="ScriptManager1" runat="server" />
            
            <ext:Panel runat="server" ID="panelInsert" Frame="true" Height="187">
                <Body>
                    ...
                </Body>
                <Buttons>
                    <ext:Button ID="btnInsert" runat="server" Text="Save" AutoPostBack="false" Icon="BulletDisk">
                        <AjaxEvents>
                            <Click OnEvent="OnbtnInsertClick" Buffer="270" >
                                <EventMask ShowMask="true" />
                            </Click>
                        </AjaxEvents>
                    </ext:Button>
                                   
                </Buttons>
            </ext:Panel>
        </form>
    </body>
    </html>
    When I want close this window (the parent window), I clic on btnInsert and execute this C# code:

     ScriptManager1.AddScript(string.Format("updateParentWindow();"));
    All this codes found correcly with IExplore, but when I use other browsers as Chrome or Firefox it isn't work and I can't close the window.

    Could you help me to solve this problem, please? :confused:
  2. #2
    Ok. I found out that javascript click event doesn't work in Chrome and Firefox.

    So, Could anyone tell me how to execute an event in a parent page from a chid page, please? It's very important to me solve this problem.

    Thank you for your time. I apologize for the inconvenience.
  3. #3
    Hi,

    You should be able to just call the following from the child page.

    Example

    parent.ExtWindowInsert.hide();
    The "btnHideExtWindowInsert" object is not an Html Element, so using .getElementById will not return the correct item. You can get an instance of the "btnHideExtWindowInsert" object by using the variable name btnHideExtWindowInsert.

    Hope this helps.
    Last edited by geoffrey.mcgill; Nov 22, 2010 at 11:17 AM.
    Geoffrey McGill
    Founder
  4. #4
    Quote Originally Posted by geoffrey.mcgill View Post
    Hi,

    You should be able to just call the following from the child page.

    Example

    parent.ExtWindowInsert.hide();

    The "btnHideExtWindowInsert" object is not an Html Element, so using .getElementById will not return the correct item. You can get an instance of the "btnHideExtWindowInsert" object by using the variable name btnHideExtWindowInsert.

    Hope this helps.
    Thank you very much geoffrey.mcgill for your answer.

    I tried your code with JavaScript but it didn't work so I supposed that I should use it with c#.

    The problem is that if I write parent.ExtWindowInsert.hide, 'ExtWindowInsert' is not recognized because the parent page is assigned during the application execution (you can show the function LoadExtWindowInsert() in my first thread).

    Or perhaps I didn't understand your explanation very well and my practice is wrong.
  5. #5
    If using Javascript is no useful in this case, do you recommend another language o technology to achieve do it?

Similar Threads

  1. [CLOSED] Problem with Firefox and Chrome
    By Stefanaccio in forum 1.x Legacy Premium Help
    Replies: 6
    Last Post: Dec 07, 2011, 12:43 PM
  2. Problem with a example in Chrome and Firefox...
    By Tanielian in forum 1.x Help
    Replies: 2
    Last Post: Apr 07, 2011, 6:14 PM
  3. Replies: 2
    Last Post: Feb 05, 2010, 5:20 PM
  4. Close Parent Window from Autoload iFrame
    By Tbaseflug in forum 1.x Help
    Replies: 3
    Last Post: Nov 16, 2009, 11:51 AM
  5. Replies: 1
    Last Post: Apr 01, 2009, 12:24 PM

Posting Permissions