By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,382 Members | 1,631 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,382 IT Pros & Developers. It's quick & easy.

Window.close()

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: 1
<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.