Click to See Complete Forum and Search --> : Close a window programatically?
chadorbaf
06-10-2003, 07:08 PM
Hi,
I have a jsp/html page that is doing something and suppose to close itself after the work down. I put window.close() in onload event on <Body> tag but received following prompt message and manually must click on YES button to close the window.
The web page you are viewing is trying to close the window?
Do you want to close this window?
Yes.. No...
How could i close this window automatically ( programatically)? Or how could i bypass this message prompt?
----------- here is the sample page -----------------
<HTML>
<HEAD><TITLE> First Page</TITLE></HEAD>
.....
..... Here doing some work
....
<BODY onload="window.close()" >
<H3>
All work down.
</H3>
<H2>
The current time is:
</H2>
<P>
<% out.println((new java.util.Date()).toString()); %>
</P>
</BODY>
</HTML>
Originally posted by chadorbaf
How could i close this window automatically ( programatically)?That is what window.close() is...
Originally posted by chadorbaf
Or how could i bypass this message prompt?It can only be bypassed with a hack, as it is a security feature. window.close() was only meant to close windows opened with javascript.
chadorbaf
06-11-2003, 09:35 AM
I tried all window.close(), self.close() and close(). But prompt me as i explained above. That's what i don't want, if possible.
AdamGundry
06-11-2003, 11:16 AM
As Pyro said, you have to open the window with Javascript in order to close it without the prompt. Why would you need to close a window you haven't opened?
Adam
chadorbaf
06-11-2003, 12:25 PM
This window opens via a batch file by windows scheduler at a certain times during the day. I want to close it after the job is done programatically.
Khalid Ali
06-11-2003, 12:46 PM
Just in case you guys want to see a solution to this crappy IE specific message..please take a look at this link.
http://68.145.35.86/skills/javascripts/SelfClosingWindowWithoutMessage.html
Yeah, I know the hack, but in Mozilla, you can't close them (non-javascript opened windows) at all, without the hack...right? That is why I didn't post how to do it...
chadorbaf
06-11-2003, 01:26 PM
Is any way in IE to do this?Could you please explain more?
Khalid Ali
06-11-2003, 01:28 PM
Originally posted by chadorbaf
Is any way in IE to do this?Could you please explain more?
Did you guys even tried the link..with IE and NS?
What Khalid posted works perfectly....
chadorbaf
06-11-2003, 03:28 PM
Originally posted by pyro
What Khalid posted works perfectly....
How we can see the code for this?
Go to Khalid's page and view source...
diamonds
06-11-2003, 04:36 PM
If javascript opens a window, it can close it without that silly question box.
for example, if var newwin=window.open(URL,'newwin') to open a window named newwin i can use newwin.close() to close it.
sorry if my syntrax isent right;)
Well obviously, it is not a javascript opened window, or he woudn't be getting the alert... :rolleyes:
chadorbaf
06-11-2003, 07:28 PM
Originally posted by pyro
Go to Khalid's page and view source...
view source doesn't work on this page.
Khalid Ali
06-11-2003, 07:46 PM
I just checked with Both NS6+ and IE6+ I can view src...if your IE is crapping out on you..try using netscape or any other browser.
AdamGundry
06-12-2003, 07:57 AM
That's an interesting hack, I must remember it. It works in Mozilla 1.3 for both tabs and windows. As you can't view source (I don't know why) I believe the line you need is:
window.opener = top;
before your window.close().
Thanks, Khalid.
Adam
chadorbaf
06-12-2003, 09:49 AM
[QUOTE]Originally posted by AdamGundry
window.opener = top;
before your window.close().
That's it. Works perfect, thanks.
Khalid Ali
06-12-2003, 10:37 AM
:D :D
You are welcome Guys
:D :D
BTW you are welcome too
chadorbaf
I think the code
window.opener=top ;
window.close() ;
doesn't work perfectly (at least with some IE version). I use IE 5 and test this code with simple htm file :
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
This window will be auto closed ???
</BODY>
</HTML>
<script language=javascript>
window.opener =top ;
window.close() ;
</script>
And I still seeing message box "Do you want to close this window ? " ???
Khalid Ali
06-13-2003, 07:27 AM
Originally posted by cat
<script language=javascript>
Try not to use the script tag as above,instead try it like line below
<script type="text/javascript">
Now this code should work for most ver4+ browsers..lets see if some one else can test it with a lower <6 IE browser.
doshi_aks
06-29-2007, 10:40 AM
How to close window in mozilla firefox 2.0
doshi_aks
06-29-2007, 10:43 AM
How to close window in mozilla firefox 2.0 using javascript
we are using the following code
window.open('','_parent','');
window.close();
Please give me the any suggessions