So I'm sure some of you out there have run into a problem where you want to close a Internet Explorer window (that wasn't created via script) and get the following IE warning "Do you want to close this window?".
I've run into this problem a few times in the past, specifically trying to close a browser window that was opened with target="_blank", etc. Today's problem was related to a client side Google Earth application where placemarks were going to open a window and play a movie. The problem is that Google Earth (not to be confused with Google Maps) does not support javascript within the placemark at this time. So to open a browser, size it and remove features (ie: toolbars, etc), I had to get crafty.
What I ended up doing in the end was create a relay script. Google Earth opens a new page (using target="_blank" in the HTML) which opens my relay script. That page, in turn, opens a 'sized' popup and closes the parent (relay script). Here is where the IE warning occurs. I first tested with IE6 and easily worked my way around it by using the following browser hack:
this.focus();
self.opener = this;
self.close();
I added this after opening the new sized window. Now, when I test with Internet Explorer 7, I still get the error? Doing some Googlin', I came across a very simple solution, where we trick the browser to think that it opened the window via script, by using the following code:
window.open('','_self','');
window.close();
I wanted to keep these separate in case I run into any other IE7 bugs, so here is my basic code put together using browser detection, etc.
var file = 'movie.htm');
var ua = window.navigator.appVersion;
var msie = ua.indexOf ( "MSIE " );
var version = ua.substring(msie+5,msie+8);
var newwin = window.open(file,'pop','width=400,height=400,scrollbars=no,toolbars=no,resizable=no');
newwin.moveTo(0,0);
if (msie && version >= "7.0"){
window.open('','_self','');
window.close();
}else{
this.focus();
self.opener = this;
self.close();
}Bookmark to:
Go Back
