close current window using window.close()

S

Shang Wenbin

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.
 
A

andreister

Hope this helps:

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

..Andrew
 
A

andreister

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.
 
I

ijsaunders

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
 
S

Shang Wenbin

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
 
G

Gérard Talbot

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/DOM:window.open#FAQ

Gérard
 
R

Randy Webb

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.
 
G

Gérard Talbot

Randy Webb wrote :
ewosch said the following on 9/1/2005 3:44 AM:



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.

Gérard
 
R

Randy Webb

Gérard Talbot said the following on 9/1/2005 12:54 PM:
Randy Webb wrote :


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.....
 
G

Gérard Talbot

Randy Webb wrote :
Gérard Talbot said the following on 9/1/2005 12:54 PM:



Where?

"Using script to close the last running instance of Microsoft Internet
Explorer also opens the confirmation dialog box."
http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/close_0.asp?frame=true
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..
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/BrowserBugsSection/MSIE6Bugs/ClosingWindowsNotOpenedByJS.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/default.aspx/Channel9.InternetExplorerSecurity

I also made sure Opera dev. is aware of this close() issue.
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 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.

Gérard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top