Advertisement
RokiAdhytama

Window - Chapter 12-1

Jul 4th, 2022
1,924
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5.49 KB | None | 0 0
  1. <html xmlns="http://www.w3.org/1999/xhtml">
  2. <head>
  3. <title>Using the Window Object</title>
  4.  
  5. <script type = "text/javascript">
  6.    <!--
  7.   var childWindow; // variable to control the child window
  8.  
  9.   function createChildWindow()
  10.   {
  11.      // these variables all contain either "yes" or "no"
  12.      // to enable or disable a feature in the child window
  13.      var toolBar // specify if toolbar will appear in child window
  14.      var menuBar; // specify if menubar will appear in child window
  15.      var location; // specify if address bar will appear in child window
  16.      var scrollBars; // specify if scrollbars will appear in child window
  17.      var status; // specify if satus bar will appear in child window
  18.      var resizable; // specify if the child window will be resizable
  19.  
  20.      // determine whether the Tool Bar checkbox is checked
  21.      if ( toolBarCheckBox.checked )
  22.         toolBar = "yes";
  23.      else
  24.         toolBar = "no";
  25.  
  26.      // determine whether the Menu Bar checkbox is checked
  27.      if ( menuBarCheckBox.checked )
  28.         menuBar = "yes";
  29.      else
  30.         menuBar = "no";
  31.  
  32.      // determine whether the Address Bar checkbox is checked
  33.      if ( locationCheckBox.checked )
  34.         location = "yes";
  35.      else
  36.         location = "no";
  37.  
  38.      // determine whether the Scroll Bar checkbox is checked
  39.      if ( scrollBarsCheckBox.checked )
  40.         scrollBars = "yes";
  41.      else
  42.         scrollBars = "no";
  43.  
  44.      // determine whether the Status Bar checkbox is checked
  45.      if ( statusCheckBox.checked )
  46.         status = "yes";
  47.      else
  48.         status = "no";
  49.  
  50.      // determine whether the Resizable checkbox is checked
  51.      if ( resizableCheckBox.checked )
  52.         resizable = "yes";
  53.      else
  54.         resizable = "no";
  55.  
  56.      //display window with selected features
  57.      childWindow = window.open( "", "", "resizable = " + resizable +
  58.         ",toolbar = " + toolBar + ",menubar = " + menuBar +
  59.         ",status = " + status + ",location = " + location +
  60.         ",scrollbars = " + scrollBars );
  61.      
  62.      // disable buttons
  63.      closeButton.disabled = false;
  64.      modifyButton.disabled = false;
  65.      getURLButton.disabled = false;
  66.      setURLButton.disabled = false;
  67.   } // end function createChildWindow
  68.  
  69.   // insert text from the textbox in the child window
  70.   function modifyChildWindow()
  71.   {
  72.      if ( childWindow.closed )
  73.         alert( "You attempted to interact with a closed window" );
  74.      else
  75.         childWindow.document.write( textForChild.value );
  76.   } // end function modifyChildWindow
  77.  
  78.   // close the child window
  79.   function closeChildWindow()
  80.   {
  81.      if ( childWindow.closed )
  82.         alert( "You attempted to interact with a closed window" );
  83.      else
  84.         childWindow.close();
  85.  
  86.      closeButton.disabled = true;
  87.      modifyButton.disabled = true;
  88.      getURLButton.disabled = true;
  89.      setURLButton.disabled = true;
  90.   } // end function closeChildWindow
  91.  
  92.   // copy the URL of the child window into the parent window�s myChildURL
  93.   function getChildWindowURL()
  94.   {
  95.      if ( childWindow.closed )
  96.         alert( "You attempted to interact with a closed window" );
  97.      else
  98.         myChildURL.value = childWindow.location;
  99.   } // end function getChildWindowURL
  100.  
  101.   // set the URL of the child window to the URL
  102.   // in the parent window�s myChildURL
  103.   function setChildWindowURL()
  104.   {
  105.      if ( childWindow.closed )
  106.         alert( "You attempted to interact with a closed window" );
  107.      else
  108.         childWindow.location = myChildURL.value;
  109.   } // end function setChildWindowURL
  110.   //-->
  111. </script>
  112.  
  113. </head>
  114.  
  115. <body>
  116. <h1>Hello, This is the main window</h1>
  117. <p>Please check the features to enable for the child window<br/>
  118.    <input id = "toolBarCheckBox" type = "checkbox" value = ""
  119.      checked = "checked" />
  120.       <label>Tool Bar</label>
  121.    <input id = "menuBarCheckBox" type = "checkbox" value = ""
  122.      checked = "checked" />
  123.       <label>Menu Bar</label>
  124.    <input id = "locationCheckBox" type = "checkbox" value = ""
  125.      checked = "checked" />
  126.       <label>Address Bar</label><br/>
  127.    <input id = "scrollBarsCheckBox" type = "checkbox" value = ""
  128.      checked = "checked" />
  129.       <label>Scroll Bars</label>
  130.    <input id = "statusCheckBox" type = "checkbox" value = ""
  131.      checked = "checked" />
  132.       <label>Status Bar</label>
  133.    <input id = "resizableCheckBox" type = "checkbox" value = ""
  134.      checked = "checked" />
  135.       <label>Resizable</label><br/></p>
  136.  
  137. <p>Please enter the text that you would like to display
  138.    in the child window<br/>
  139.    <input id = "textForChild" type = "text"
  140.      value = "<h1> Hello, I am a child window</h1> <br\>"/>
  141.    <input id = "createButton" type = "button"
  142.      value = "Create Child Window" onclick = "createChildWindow()" />
  143.    <input id= "modifyButton" type = "button" value = "Modify Child Window"
  144.      onclick = "modifyChildWindow()" disabled = "disabled"/>
  145.    <input id = "closeButton" type = "button" value = "Close Child Window"
  146.      onclick = "closeChildWindow()" disabled = "disabled"/></p>
  147.  
  148. <p>The other window's URL is: <br/>
  149.    <input id = "myChildURL" type = "text" value = "./"/>
  150.    <input id = "setURLButton" type = "button" value = "Set Child URL"
  151.      onclick = "setChildWindowURL()" disabled = "disabled"/>
  152.    <input id = "getURLButton" type = "button" value = "Get URL From Child"
  153.      onclick = "getChildWindowURL()" disabled = "disabled"/></p>
  154.    
  155. </body>
  156. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement