JS: Opening and Closing Windows

by "Pietro De Santis" <marf2000(at)home.com>

 Date:  Tue, 19 Sep 2000 12:24:13 -0400
 To:  "HWG Techniques" <Hwg-Techniques(at)mail.hwg.org>
  todo: View Thread, Original
Hello,

I have an intranet site where a user accesses reports from a menu. When the
report link is clicked, a new window is opened, with a link back to the
menu. When the menu link is clicked on the report window, the report window
is closed and the menu window is brought forward.

My problem is that if the user closes the menu window and then clicks on the
menu link on the report window, I get a JavaScript error, because the menu
window is closed.

I thought I could track the status of each window by setting variables, but
this does not work. The opener menu window does not seem to set the
variables in the opened report window and vice versa.

If someone has an easier method, I'd be grateful for a few ideas.

The environment is IE4.

I have included here the HTML code for the two windows. Please forgive the
lengthy e-mail.

Thanks,

Pietro.

MenuOne.html

<html>
  <head>
    <title> Menu One </title>
    <script language="JavaScript">
      // Declare window tracking variables
      var ReportWinStatus = 'closed';

      var MenuURL = document.URL;

      function OpenReport(ReportWin)
      {
      var vFeatures = "height=" + screen.availHeight + ",left=0,";
      vFeatures    += "location=no,menubar=no,resizable=yes,scrollbars=yes,"
      vFeatures    += "status=yes,titlebar=yes,toolbar=no,";
      vFeatures    += "top=0,width=" + screen.availWidth;

      ReportWin = window.open(ReportWin,"ReportWin",vFeatures);

      // Set window tracking variables
      ReportWin.MenuWinStatus = "open";
      ReportWin.MenuWin       = MenuURL;

      ReportWin.moveTo(0,0);
      ReportWin.resizeTo(screen.availWidth,screen.availHeight);
      ReportWin.focus();
      }

      function CloseMenuWin()
      {
      if (ReportWinStatus == 'open') ReportWin.MenuWinStatus = 'closed';
      }
    </script>
  </head>

<body onUnload="JavaScript:CloseMenuWin();">
  <a href="JavaScript:OpenReport('ReportOne.html');">Open Report One</a>
</body>
</html>

ReportOne.html

<html>
  <head>
    <title> Report One </title>
    <script language="JavaScript">
      // Declare window tracking variables
      var MenuWinStatus;
      var MenuWin;

      function SetReportWinStatus(Status)
      {
      if (MenuWinStatus == 'open') opener.ReportWinStatus = Status;
      }

      function goHome()
      {
      if (MenuWinStatus == 'open')
        {
        window.opener.focus();
        window.close();
        }
      else
        {
        window.close();
        window.open(MenuWin,"MenuWin");
        window.moveTo(0,0);
        window.resizeTo(screen.availWidth,screen.availHeight);
        }
      }
    </script>
  </head>

<body onLoad="JavaScript:SetReportWinStatus('open');"
      onUnload="JavaScript:SetReportWinStatus('closed');">
  <a href="JavaScript:goHome();">Return to Menu</a>
</body>
</html>

HWG hwg-techniques mailing list archives, maintained by Webmasters @ IWA