Using JavaScript in a different HTML file than Reflection

In this example, JavaScript is used to interact with a Reflection terminal session applet embedded in a browser window frameset. The applet is in one HTML file, which is displayed in the lower frame of the frameset file, and the JavaScript code is in a different HTML file, which is displayed in the upper frame. Comments in the JavaScript explain the action. Also see the example of using JavaScript in the same HTML file as Reflection.

First, here's the HTML for the frameset file:

   <html>
   <frameset rows="50,*">
       <frame name="codeframe" src="codeframe.html">
       <frame name="appletframe" src="appletframe.html">
   </frameset>
   </html>

Next, here's the HTML for the codeframe.html file, which is the upper frame of the frameset and contains the JavaScript code:

   <html>
   <head>
   <title>Code Frame</title>
   <script language="JavaScript">
   <!--
         /*
          The variable "target" holds a reference to the terminal session
          applet in the lower frame. When the script first runs, the setTarget() function
          executes to set the target variable.
       */
       var target;
       setTarget();

       /*
          This function sets the variable "target" to refer to the terminal
          session applet in the lower frame. The full window and document hierarchy
          that identifies the location of the applet is required. If the applet is
          not yet loaded and the target is null, a timeout is used to continually
          check for the applet again, waiting 1 second between tries.
       */
       function setTarget()
       {
           target = parent.appletframe.document.IBM3270Applet;
           if ( target == null )
           {
               setTimeout( "setTarget()", 1000 );
           }
       }
      
       /*
          This function opens Reflection's Color Setup dalog box
          when the user clicks the Color Setup button. The notation
          "target.showDialog( "colorConfigure" )" uses the target variable
          defined earlier, providing an easier way of specifying
          "parent.appletframe.document.IBM3270Applet.getAPI("JSAPI","IBM3270").showDialog( "colorConfigure" )".
       */
       function doColorSetup()
       {
           target.getAPI("JSAPI","IBM3270").showDialog( "colorConfigure" );
       }
   
       /*
          This function opens Reflection's Button Palette Setup dialog box when the user clicks the Button Setup button. The notation
          "target.showDialog( "buttonPaletteConfigure" )" uses the target variable
          defined earlier, providing an easier way of specifying
          "parent.appletframe.document.IBM3270Applet.getAPI("JSAPI","IBM3270").showDialog( "buttonPaletteConfigure" )".
       */
       function doButtonSetup()
       {
           target.getAPI("JSAPI","IBM3270").showDialog( "buttonPaletteConfigure" );
       }
   // -->
   </script>
   </head>
   <body>
   
   <!-- 
      <Form> buttons give the user access to the Color Setup and
      Button Palette Setup dialog boxes. When the onClick event handler
      is invoked, one of the JavaScript functions defined above is
      called.
   -->
   <form>
   <input type="button" Name="ColorSetup" Value="Color Setup" onClick="doColorSetup()">
   <input type="button" Name="ButtonSetup" Value="Button Setup" onClick="doButtonSetup()">
   </form>
    </body>
   </html>

Lastly, here's the HTML for the appletframe.html file, which appears in the lower frame of the frameset and contains the Reflection terminal session applet--make sure to change the hostURL parameter in the <applet> tag to a host appropriate for your network:

   <html>
   <head>
   <title>Applet Frame</title>
   </head>
   <body>
   
   <!-- 
      The <applet> tag defines a simple Reflection applet for
      IBM 3270 emulation. To use this example, change the hostURL
      parameter to one appropriate for your network.
   -->
   <applet mayscript name="IBM3270Applet"
           codebase="./ex/" 
           code="com.wrq.rweb.Launcher.class" width="800" height="500"
           archive="Launcher.jar">
       <param name="hostURL" value="tn3270://payroll">
       <param name="autoconnect" value="true">
       <param name="frame" value="false">
     <param name="launcher.sessions" value="IBM3270">
       <param name="preloadJSAPI" value="true">
   </applet> 
   
   </body>
   </html>