Pop up window not closing

  • Thread starter Thread starter tshad
  • Start date Start date
T

tshad

I have a couple of windows I am opening from my .aspx window and want the
child windows to close when the browser closes or I change pages.

I have the following to open the window:

function OpenLogoPreviewWindow()
{
window.open('logoDisplay.htm','myWindow','menubar=no,toolbar=no,directories=no,resizable=no,scrollbars=no,location=no,status=no');}And in my Page_Load routine I have the following to add to my body tag: myBody.attributes.Add("onUnload","myWindow.close()")And when I do a view source the body tag shows as:<body id="myBody" onUnload="myWindow.close()">But the window stays open when I go to a new page of close the window. Ialso tried to set a timer to close the window but it won't close either.Is this something from Asp.Net that is stopping this?ThanksTom
 
Howdy,

This is because 'myWindow' is undefined identifier (it is not automatically
added to properties of the current window). I changed the code so it will
handle
as many windows as you create:


<body onunload="CloseOpenedWindows()">
<form id="form1" runat="server">

<button onclick="OpenLogoPreviewWindow()">Create a window</button>
<script type="text/javascript">

var openedWindows = new Object();

function OpenLogoPreviewWindow()
{
var wndName = 'myWindow';
var wnd =
window.open('http://www.wp.pl',wndName,'menubar=...ble=no,scrollbars=no,location=no,status=no');
if (wnd)
{
eval('openedWindows.' + wndName + ' = wnd;');
}
else
{
alert('please unblock popup blockers');
}
}
function CloseOpenedWindows()
{
for (var wndName in openedWindows)
{
openedWindows[wndName].close();
}
}
</script>

</form>
</body>
 
Thomas Hansen said:
I have a couple of windows I am opening from my .aspx window and want the
[snip]

Don't use popup windows, use: http://ajaxwidgets.com/
AllControlsSamples/Window.aspx

Looks pretty good.

But the objects seem to be for Asp.net 2.0 and I am using 1.1.

Also, I use an ajax style program called Anthem that works really well.
Would these objects have a problem with this?

Thanks,

Tom
 
That was what I was looking for.

I didn't realize I had to actually define the window. I thought my open
window call was doing it.

Thanks,

Tom
Milosz Skalecki said:
Howdy,

This is because 'myWindow' is undefined identifier (it is not
automatically
added to properties of the current window). I changed the code so it will
handle
as many windows as you create:


<body onunload="CloseOpenedWindows()">
<form id="form1" runat="server">

<button onclick="OpenLogoPreviewWindow()">Create a window</button>
<script type="text/javascript">

var openedWindows = new Object();

function OpenLogoPreviewWindow()
{
var wndName = 'myWindow';
var wnd =
window.open('http://www.wp.pl',wndName,'menubar=...ble=no,scrollbars=no,location=no,status=no');
if (wnd)
{
eval('openedWindows.' + wndName + ' = wnd;');
}
else
{
alert('please unblock popup blockers');
}
}
function CloseOpenedWindows()
{
for (var wndName in openedWindows)
{
openedWindows[wndName].close();
}
}
</script>

</form>
</body>

--
Milosz


tshad said:
I have a couple of windows I am opening from my .aspx window and want the
child windows to close when the browser closes or I change pages.

I have the following to open the window:

function OpenLogoPreviewWindow()
{

window.open('logoDisplay.htm','myWindow','menubar=no,toolbar=no,directories=no,resizable=no,scrollbars=no,location=no,status=no');}And
in my Page_Load routine I have the following to add to my body tag:
myBody.attributes.Add("onUnload","myWindow.close()")And when I do a view
source the body tag shows as:<body id="myBody"
onUnload="myWindow.close()">But the window stays open when I go to a new
page of close the window. Ialso tried to set a timer to close the window
but it won't close either.Is this something from Asp.Net that is stopping
this?ThanksTom
 
Back
Top