Nov 15, 2010, 8:09 AM
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:
The code of the external page is the next:
ASPX:
Could you help me to solve this problem, please? :confused:
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: