Entry
Is it possible to avoid the close window confirmation dialog?
Nov 22nd, 2008 02:13
Raj Aryan, HeadCircus, Michel Plungjan, Dave Heslop, Adam Baruch, Mohan Sundaram, Jason Alphonse, Kalin Shanklin, Martin Honnen,
If JavaScript tries to close a window it didn't originally open the
browser pops up a confirmation dialog for the user to agree on closing
the window.
Avoiding that is only possible with trusted script in NN4 and with a
signed active x control like wpm of www.meadroid.com in IE4+.
Here is the code for NN4:
netscape.security.PrivilegeManager.enablePrivilege(
'UniversalBrowserWrite'
);
window.close();
Note that unless you have successfully requested the privilege before
a
dialog will pop up to grant the privilege so you are only replacing
one
dialog with another.
There is another method for closing out the window, however I have yet
to get it to work with IE, works well on NN4 though, and it does NOT
require signed scripts.
The following is a hypothetical sittuation involving 2 html files:
JoeSurfer clicks on a link that brings him to your first page
(index.htm). Index.htm has the following code in its header:
<script language="javascript">
<!--
function killHistory(){
location.replace("index2.htm")
}
killHistory();
//-->
</script>
This code bounces the page to a new location of index2.htm. Index2.htm
has the following code:
<script language="javascript">
<!--
function openMain() {
new_win = window.open('popup.htm','popup','whole lot of specifications
here');
}
openMain();
window.self.close();
//-->
</script>
This script pops open a NEW window and closes itself, WITHOUT the
confirm dialog.
This is just how I used it, rather then using "self.close" you can
also
use the opener property (opener.close) from the popup window to close
it, or you can dispense with the popup and close the window from
itself by way of an event(eg: a link). So long as you have the first
page redirecting to a new page, with the "location.REPLACE" method(and
wipeing out the history), you can close the original window in NN
without the confirm. I have yet to get this to work with IE though.
----
Here's an interesting quirk:
The following code works in NN4+, IE 4+, and Opera 5 Win (at least).
<script>
daddy = window.self;
daddy.opener = window.self;
daddy.close();
</script>
---
J.A.
I tried something interesting. I figured that IE asks for confirmation
only if window.opener is null - the case when an IE window is opened
thro' the desktop. Windows opened thro' js have a value in
window.opener and hence can get closed. I tried just assigning
window.opener to a constant and closed the window. It worked! By the
same logic, if we set window.opener to null, IE will not close the
window without a prompt. This can be used to prevent malicious js
close?
<script>
window.opener = 'm';
window.close();
</script>
Mohan
Well I tried both above "solutions" (using window.opener) and they
definitely DO NOT work in IE5+
Any further siggestions?
Adam
----------------------------------------
Using it successfully to log my ip when my pc boots, saves me
requiring dynamic dns for my server. I haven't tested it on anything
other than Win XP and IE6 because that is all i need it for, so
apologies if it does not work for you.
<body onLoad="window.opener=null; window.close(); return false">
(NOTE: I suggest you open this link in a new window, because it will
close)
DEMO URL:
http://www.daveheslop.co.uk/SOLUTIONS/windowclose.php
Dave
---------------------------------------
I personally hate this code. Just a matter of time before uninformed or
malicious people use it to force their view of the world on us.
I even recommend it removed from this site. It is an unsupported hack in
the family of Denial Of Service attacks and should never be used by
anyone.
Michel
---------------------------------------
This test will give you more a bit more flexibility when a window is
used in more than one arrangement which may or may not include:
- windows that hijack others in one interactive session
- launching windows from java applets
The difference is that window x is an actor in several different
scenarios and may have a parent or not.
if(!window.opener){
window.opener = ''
}
self.close()
Head
---------------------------------------
http://www.webs4soft.com/Links4.htm
http://hotelsinindia.webs4soft.com/hotels-in-delhi.htm
http://indiatravel.webs4soft.com/Resources.htm
http://indianmovies.webs4soft.com/Kuch-Kuch-Hota-Hai.htm
http://real-estate.webs4soft.com/property-tips.htm
http://foodhealthcaretips.webs4soft.com/Resources.htm
http://www.websitecompanyindia.com/seo-Links.htm
http://www.websitecompanyindia.com/seo-Links.htm
http://indianjewelry.websitecompanyindia.com/dimond-ring.htm
http://www.bestindiaeducation.com/Link-Exchange.htm
http://bestjobconsultant.bestindiaeducation.com/PARTNERS.htm
http://eloctronicandmobilestore.bestindiaeducation.com/mobile-links.htm
http://easyloanservice.bestindiaeducation.com/Home-Insurance-Links.htm
http://www.rajhealthcenter.com/Cosmetic-Surgery.htm
http://creativebusinessgroup.rajhealthcenter.com/Business-Links.htm
http://onlinefreeinternetgames.rajhealthcenter.com/Games-Links.htm
http://top-beauty-tips.rajhealthcenter.com/Beauty-Links.htm
http://www.indiatourpoint.com/Travel-Links.htm
http://four-wheeler-buy-tips.indiatourpoint.com/Auto-Links.htm
http://watch-online-free-cricket-match.indiatourpoint.com/Sports-Links.htm
http://directory.indiatourpoint.com/
http://www.bestlifeindia.com/Resources1.htm
http://directory.bestlifeindia.com/
http://freeorkutscrapandsms.bestlifeindia.com/SMS-Links.htm
http://onlinegiftshop.bestlifeindia.com/Gift-Links.htm
http://www.freemusicpoint.com/Music-Links.htm
http://love-dating.freemusicpoint.com
http://online-art-presentation.freemusicpoint.com/
http://onlinefurnitureshop.freemusicpoint.com/