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

close current window using window.close()

P: n/a
Hi,
When I want to close the current window using window.close() in IE6.0,
there will be a confirm box that: The web page you are viewing is trying
to close the window. Do you want to close this window?
I have to click yes to close the window.
How can I close the current window directly without this dialog box?

Thank you.
Sep 1 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
Hope this helps:

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

..Andrew

Sep 1 '05 #2

P: n/a
This alert occurs only if there is only one window and cannot be
switched off.

Sep 1 '05 #3

P: n/a
Are you sure?
I guess it could be security-dependent, but the approach is not clear
enough.

The notorious code below does not work in Firefox :))

==========
<html>
<body onclick="alert('ooops'); window.opener=self; window.close();">
Click this page and window.close() is called.
</body>
</html>
=========

Nevertheless, I've checked it in Opera and IE, both succeeded.

Sep 1 '05 #4

P: n/a
closing popup windows (child windows) is acceptable, but the content
controlling the browser is not really good web practice.

I can think of instances when this would be helpful, but you should not
depend on it. Especially as the users may not have javascript, ot they
could have disabled it.

Ian
www.boan-design.co.uk

Sep 1 '05 #5

P: n/a
an********@gmail.com wrote:
Hope this helps:

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

.Andrew


Ok, this works for me
I only want it to work in IE, and I'll use other method for firefox

thanks Andrew and andreister
thanks all
Sep 1 '05 #6

P: n/a
Shang Wenbin wrote :
Hi,
When I want to close the current window using window.close() in IE6.0,
there will be a confirm box that: The web page you are viewing is trying
to close the window. Do you want to close this window?
I have to click yes to close the window.
How can I close the current window directly without this dialog box?

Thank you.


1st question in the FAQ on window.open():
http://developer.mozilla.org/en/docs...indow.open#FAQ

Gérard
--
remove blah to email me
Sep 1 '05 #7

P: n/a
ewosch said the following on 9/1/2005 3:44 AM:
This alert occurs only if there is only one window and cannot be
switched off.


That is far from the truth.

It does work if there are more than one window.
It *can* be switched off.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Sep 1 '05 #8

P: n/a
Randy Webb wrote :
ewosch said the following on 9/1/2005 3:44 AM:
This alert occurs only if there is only one window and cannot be
switched off.

That is far from the truth.

It does work if there are more than one window.
It *can* be switched off.


That's is already mentioned in MSDN documentation too. People way
over-want to kill opener windows but this goes against the best
interests of the users. Expect MSIE 7 to put an end to all this (wink)
and expect your scripts to fail closing such IE 7 windows. Mozilla-based
browsers already deny the capability to close such windows; reasonable
and responsible web designers don't try to close non-script-initiated
windows.

Grard
--
remove blah to email me
Sep 1 '05 #9

P: n/a
Grard Talbot said the following on 9/1/2005 12:54 PM:
Randy Webb wrote :
ewosch said the following on 9/1/2005 3:44 AM:
This alert occurs only if there is only one window and cannot be
switched off.
That is far from the truth.

It does work if there are more than one window.
It *can* be switched off.


That's is already mentioned in MSDN documentation too.


Where?

People way over-want to kill opener windows but this goes against the best
interests of the users.
That depends on the user I guess.
Expect MSIE 7 to put an end to all this (wink) and expect your scripts
to fail closing such IE 7 windows.
Somehow, I doubt it but would be totally shocked if it does. Considering
that IE has had that bug since IE5 or so, and it hasn't been fixed
through 3 versions, I don't see them fixing it now. That would require
MS to admit they had flawed software and actually fix it.
Mozilla-based browsers already deny the capability to close such windows;
Don't bet on it.
reasonable and responsible web designers don't try to close
non-script-initiated windows.


"reasonable and responsible web designers" don't use secondary windows,
so they have no need to close superficial windows.....
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Sep 1 '05 #10

P: n/a
Randy Webb wrote :
Grard Talbot said the following on 9/1/2005 12:54 PM:
Randy Webb wrote :
ewosch said the following on 9/1/2005 3:44 AM:

This alert occurs only if there is only one window and cannot be
switched off.


That is far from the truth.

It does work if there are more than one window.
It *can* be switched off.

That's is already mentioned in MSDN documentation too.

Where?


"Using script to close the last running instance of Microsoft Internet
Explorer also opens the confirmation dialog box."
http://msdn.microsoft.com/workshop/a...asp?frame=true
People way over-want to kill opener windows but this goes against the
best
interests of the users.

That depends on the user I guess.


I make a general rule, a generalization if you prefer, from this.
Any/every window has a system command close [x] button on the titlebar.
So why do scripters need to provide me with links, buttons, etc.. to
close that window. If I can open a new window on my own, I certainly can
close a secondary window on my own. Same thing with closing the internet
connection, shutting down the PC, closing the tv, etc.. I do not need
any additional, extra help in managing (open, resize, move and close)
windows which should be under my complete and entire control to begin
with. Browser manufacturers (Mozilla, Opera, Microsoft, Safari,
Konqueror, etc) understand such perspective and agree with it and they
are providing users with veto powers over script methods like open(),
resizeTo, moveTo, resizeBy, resizeTo, close, etc..
Expect MSIE 7 to put an end to all this (wink) and expect your scripts
to fail closing such IE 7 windows.

Somehow, I doubt it but would be totally shocked if it does. Considering
that IE has had that bug since IE5 or so, and it hasn't been fixed
through 3 versions, I don't see them fixing it now. That would require
MS to admit they had flawed software and actually fix it.


They can fix the bug without admitting anything seriously detrimental
too; security is a concern for all browser manufacturers and for
web-aware software makers. I created a page back 1-2 years ago with your
own data, Randy:

http://www.gtalbot.org/BrowserBugsSe...penedByJS.html

and then posted a request (see/search for: "opener property should be a
read-only property") in that sense at:

http://channel9.msdn.com/wiki/defaul...plorerSecurity

I also made sure Opera dev. is aware of this close() issue.
Mozilla-based browsers already deny the capability to close such
windows;

Don't bet on it.


Current Mozilla-based browsers do deny the capability to close such windows.
The default setting of dom.allow_scripts_to_close_windows in
about:config is false.

reasonable and responsible web designers don't try to close
non-script-initiated windows.

"reasonable and responsible web designers" don't use secondary windows,
so they have no need to close superficial windows.....


I would add one nuance to such statement but I'd rather not since I
fully (general rule) support this opinion.

Grard
--
remove blah to email me
Sep 2 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.