DevSnips.com Code Snippet Repository
search:    


Navigation
  Home
About
Library
Contact
 
Snippet Library
  ColdFusion   338  
  ASP   201  
  PHP   101  
  HTML   11  
  JavaScript   77  
  XML   2  
  CSS   5  
  SQL   13  
  JSP   2  
  C#   1  
  ASP.NET   0  
  Submit a Code Snippet
 
Blog Archive
  September 2007
August 2007
July 2007
June 2007
May 2007
November 2006
October 2006
Search Archives
 
Random Affiliates
  BioMetric Base
PHP Arch
Uno-Code
ReviewMe!

Want to become an affiliate?
Read more...


Privacy Policy
© 2008

Blog Archive

 
"Do you want to close this window?" IE 7 Fix

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();
}


Submitted on 05/31/07 at 11:05AM
Post Comment | Comments: 0
Bookmark to:
Add ' Add ' Add ' Add ' Add ' Add ' Add ' Add ' Add ' Add ' Add ' Add ' Add ' Add ' Add ' Add ' Add ' Add ' Add ' Add ' Add ' Add ' Add ' Add '

Go Back








Advertisements

Get Any Game Free with GamePass