472,121 Members | 1,578 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,121 software developers and data experts.

Window.close()

Hello

I have some trouble in closing a window, Here is the problem:

I develop a asp.net website use client side valiation

<asp:CustomValidator id="CustomValidator1"
ControlToValidate="Text1"
ClientValidationFunction="BasicSearchValidation"
OnServerValidate="ServerValidation"
Display="Static"
ErrorMessage="Not an even number!"
ForeColor="green"
Font-Name="verdana"
Font-Size="10pt"
runat="server"/>
the validation function (JavaScript) is

BasicSearchValidation(source, arguments)
{
...

w1 = window.open("PopupErrorMsg.htm", "example1", "width=400,
height=300, location=no, menubar=no, status=no, toolbar=no,
scrollbars=no, resizable=no");
...
}

ASP.net will automatically call BasicSearchValidation and open a
window,
but when I click close button on the window, it always prompt a
messagebox to ask me to close it. How can I close the window without
the prompting the messagebox?

Thanks!
John
Jul 20 '05 #1
4 21899
DU
John H. wrote:
Hello

I have some trouble in closing a window, Here is the problem:

I develop a asp.net website use client side valiation

<asp:CustomValidator id="CustomValidator1"
ControlToValidate="Text1"
ClientValidationFunction="BasicSearchValidation"
OnServerValidate="ServerValidation"
Display="Static"
ErrorMessage="Not an even number!"
ForeColor="green"
Font-Name="verdana"
Font-Size="10pt"
runat="server"/>
the validation function (JavaScript) is

BasicSearchValidation(source, arguments)
{
...

w1 = window.open("PopupErrorMsg.htm", "example1", "width=400,
height=300, location=no, menubar=no, status=no, toolbar=no,
scrollbars=no, resizable=no");
...
}

You must make the window object reference as a global variable,
otherwise you won't be able to reference it from outside its function
for blur(), focus(), closed and close() methods and properties.

You must remove blank space between the windowFeatures string list in
the 3rd argument, otherwise such windowFeature requests won't be honored
in NS.
"windowFeatures is an optional string containing a comma-separated list
of options for the new window (do not include any spaces in this list)."
http://devedge.netscape.com/library/...w.html#1202731
Note here that either way, you are removing basic normal browser window
functionalities (resizability and scrollbars presence if needed, that is
if content overflows window dimensions) from your popup which is
definitively not recommendable (accessibility to content and usability).
You can not force the statusbar to be hidden for NS 6+ and Mozilla-based
browsers users.

ASP.net will automatically call BasicSearchValidation and open a
window,
but when I click close button on the window
On which window exactly? window.close(), self.close(), w1.close() are 3
different calls depending on where you make such call. Here, in your
code, we have no clues at all on how and where you may be making which call.

, it always prompt a messagebox to ask me to close it. How can I close the window without
the prompting the messagebox?

Thanks!
John


Check the FAQ on this.
http://jibbering.com/faq/
A window not opened by javascript can NOT be closed by javascript
because it can not be referenced with client-side javascript.

DU
---------------------------
Javascript and Browser bugs:
http://www10.brinkster.com/doctorunclear/

Jul 20 '05 #2
In article <bd**********@news.eusc.inter.net>, DU <dr*******@hotREMOVEmail.com>
writes:
Check the FAQ on this.
http://jibbering.com/faq/
A window not opened by javascript can NOT be closed by javascript
because it can not be referenced with client-side javascript.


http://tinyurl.com/fiyh

Is one of many threads that discusses where it *does* work. The list
of browsers where it works seems to be growing. Perhaps its time
to add it to the FAQ?

This script:

window.opener = window;
window.close();

Results:

PC browsers:

Netscape 4.06 - Prompts the user about trying to close a window (I didn't see
this message, someone else tested it for me).
Netscape 4.80 - closes window without a prompt.
IE5.0 - prompts the user.
IE5.5 - Cant find anyone who has IE5.5 so untested there.
IE6.0 - closes window without a prompt.
Netscape 7 - closes the window without a prompt.
Opera 7 - closes the window without a prompt.
Phoenix 0.5 - closes the window without a prompt.
Mozilla 1.4 - No prompt, just an error message "Scripts may not close windows
that were not opened by script." in the Javascript console.

MAC browsers:

AOL For Mac OSX v. 10.3 - closes the window without a prompt
IE 5.2.2 for Mac - closes the window without a prompt

Netscape 7.02 for Mac OSX Does nothing, and after attempting to open,
Netscape must be rebooted

I am not the one testing on the MAC so not sure exactly what NS7.02 is doing
there. Also, it has been tested in the past in OmniWeb on a MAC and it closes
the window without a prompt but do not know the version that was used.

The results seem to indicate that the statement "javascript can't close a
window that it didn't open" a false statement, within a very few limitations.
Namely, Mozilla on a PC, preIE5.5 on PC and NS7 on the MAC. Other than that,
yes, I *can* close a window that script didn't open.

The only one I tested it in that actually surprised me was NN4.80 where it
works.
--
Randy
All code posted is dependent upon the viewing browser
supporting the methods called, and Javascript being enabled.
Jul 20 '05 #3
In article <20***************************@mb-m27.aol.com>,
hi************@aol.com (HikksNotAtHome) writes:
IE5.5 - Cant find anyone who has IE5.5 so untested there.


Was just tested on IE5.5 and it closes the window without a prompt.

Leaves it at <=IE5.0, NS7 on MAC, Mozilla 1.4 on the PC that it *doesn't* work.

Anybody that can test it in any other browsers that aren't listed?
--
Randy
All code posted is dependent upon the viewing browser
supporting the methods called, and Javascript being enabled.
Jul 20 '05 #4
<html>

<head>
<SCRIPT language="JavaScript">
<!--
var browserName=navigator.appName;
if (browserName=="Netscape") {

function closynoshowsme()
{
window.open('','_parent','');
window.close();}
}
else {
if (browserName=="Microsoft Internet Explorer")
{
function closynoshowsme()
{
window.opener = "whocares";
window.close();
}
}
}

//-->
</SCRIPT>

</head>

<body>
<a href="javascript: closynoshowsme();">Close Window</a><br /><br />
<button type="button" onclick="closynoshowsme();">Close this window</button>
</body>
</html>
Jun 15 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

14 posts views Thread by Nigel Mercier ® | last post: by
9 posts views Thread by Graham | last post: by
5 posts views Thread by lindanr | last post: by
9 posts views Thread by Stan B | last post: by
2 posts views Thread by kurt sune | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.