473,144 Members | 2,696 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,144 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 22037
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Nigel Mercier ® | last post by:
I'm just starting to learn JavaScript, so far I like it! I want to add some JS to my Ebay listings, to manually open a pop-up window. It works OK, but the JS gets rejected by Ebay. If I can't...
3
by: Steve | last post by:
Hi, I have a nice little script that works well displaying images on my website. It's a script where if you clik a thumbnail image a pop up window opens that contains a larger version of the same...
9
by: Graham | last post by:
What I currently have is a page that opens another browser at 800x600, once that is loaded I would like to close the orginal page down while keeping the page that it has just opened open (To make...
4
by: GrantS | last post by:
I am having a problem closing a popup window opened modally. When I try to close the window (when the user hits save button and the data has been processed), the Popup window opens as a full screen...
1
by: Earl Teigrob | last post by:
I did a ton of searching to try and find a simple solution to this issue and finally wrote my own, which I am sharing with everyone. In my searching, I did find a very complete and robust solution at...
2
by: Tom | last post by:
How is the best way to avoid validation when closing a window? For instance, I have a Windows Forms window which has a validation event for a text box. However, if one enters invalid data in then...
5
by: lindanr | last post by:
In ASP.NET 2005 I have an onblur="window.close()" javascript event in the <body> tag. When I click on the window's scrollbar, the window closes. The same code works fine in ASP.NET 2003. Any...
9
by: Stan B | last post by:
I create a popup window by calling window.showModalDialog Popup window has Ok button with this code attached: === string Script = "<script language=JavaScript>" + "{" + "window.close();" +...
7
by: Toccoa | last post by:
After considerable googling - I mean searching with Google(r) - I could not find javascript on a button or <a href=... to close a window in the latest versions of IE and FireFox. There seemed...
2
by: kurt sune | last post by:
Hello, I have a weird problem, I hope someone can explain this for me. I have a webpage using masterpage. In it I create a popup window using this code: Dim js As String = "<script...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...
3
by: efe2023 | last post by:
Hello Everybody, There is SQL Server 2008 R2 database with MS Access front-end (linked ODBC tables). I can see all linked tables in MS Access and can add new rows. However, when trying to update...
3
by: jimatqsi | last post by:
So, I had this bright idea today that didn't quite work out. Or maybe it is working out but requires me to change a habit. I'm working on a form that will be a sub-form of another form. During...
0
by: saichinnu1852 | last post by:
I am trying to use Collibra by installing it using AWS Marketplace AMI that they offer and launched the EC2 instance. However, when I try to login to Collibra using the IP Address of the EC2 instance...

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.