none
Window.close() in Internet Explorer 7

    Question

  • Hi,

           I am using the following code to open a new window in IE7 and then i am trying to close the parent window

    <html>

    <head>
     
     <script language="jscript">

     function openPage() {
       window.open("index.htm","_blank","top=0,left=0,width="
        + screen.width + ", height=" + screen.height
        + ",scrollbars=yes,status=no");

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

     }
     </script>
    </head>

    <body onload="openPage() ;">


    </body>

    </html>

                When I use the above HTML code , IE7 displays a prompt message saying  "The web page that you are viewing is trying to close a tab" .Is there any way to close the parent window without the prompt message being displayed???

    Thanks in Advance.

     

     

     

    Wednesday, November 08, 2006 10:20 AM

Answers

All replies

  • hi v ram,

    this is a new feature in ie7. i think microsoft thought they were clever when they implemented this.

    opening a new window and closing the parent is no longer possible without forcing user interaction.

    “IF ANYONE FINDS A WORK AROUND FOR THIS PLEASE LET ME KNOW…!”.

    i have tried testing .hta files (which there is not much information about on the web) to perform this, but have been unsuccessful thus far. i continually get xml error's, that i have not figured out yet.

    this new ie feature is extremely annoying for companies that build web applications without wanting to display navigation and address bars (which is my case). why they don't at least allow trusted websites (a feature available in ie) to use this feature is just beyond me.

    v ram, the closest thing to a solution i can find on the web at the moment is this:

    http://www.webdeveloper.com/forum/showthread.php?t=121449

    (incase this link becomes inactive, here is the code)

    window.onload = poponload;

    function poponload()

    {

    //Open new window, move topleft and maximize

    testwindow= window.open ('link', "_blank", "location=no,menubar=no,status=yes,toolbar=no,resizable=no");
    testwindow.moveTo(0,0);
    testwindow.resizeTo(window.screen.availWidth,window.screen.availHeight);


    //Set variables, version is IE version number

    var ua = window.navigator.appVersion;
    var msie = ua.indexOf ( "MSIE " );
    var version = ua.substring(msie+5,msie+8);


    //Check version number and run correct code

    if (version >= "7.0")
    {
    var obj = new ActiveXObject("Wscript.shell");

    self.opener = this;

    self.focus();

    obj.SendKeys("%{F4}");
    obj.SendKeys("%{F4}");
    }

    else

    {
    self.opener = this;

    setTimeout('self.close()',500);

    };


    }
    Friday, November 10, 2006 10:55 AM
  • I believe I may have found a workaround to this problem.  I have responded to "nath" in the following post:

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=962189&SiteID=1

    Paul

    Monday, November 27, 2006 3:50 PM