引用另一个页面并更改 iframe 内容

Referencing another page and change the iframe content

我正在尝试使用我的主页引用另一个页面并使用 JavaScript 更改该页面的 iframe 中的内容及其标题。当我已经在页面中时,我可以更改内容,但是当我从主页引用时,它不会更改 iframe 的内容。

EntryForm.html 是 'master form page' 需要能够在用户单击主页按钮时更改 iframe 的内容和标题。任何帮助表示赞赏。

首页html页面

    <!DOCTYPE html>
<html>
   <head>
      <meta charset="UTF-8"content="HTML,CSS,XML,JavaScript">
      <script src="Scripts/jquery.js" type="text/javascript"></script>
      <script src="Scripts/Global.js"></script>   
      <script type="text/javascript" src="lib/d3.js"></script>
      <script type="text/javascript" src="Scripts/gauge.js"></script>
      <link rel="stylesheet" type="text/css" href="Styles/Design.css">
   </head>
   <body onload="initialize()">
      <div id="body"><br></div>
      <div id="header">
         <h1>Carrolton Plant</h1>       
         <div id="headerIcon"></div>
         <div id="tv1clock"></div>
      </div>      
      <div id="content"> </div>
        <span id="oeeLine1GaugeContainer"></span>
        <span id="oeeLine2GaugeContainer"></span>
        <span id="oeePlantGaugeContainer"></span>
        <span id="testGaugeContainer"></span>
      <div id="footer">&nbsp;
         <input title="Home Page" type="homebutton"></input>
         <input title="Previous Page" type="previousbutton" onclick="PreviousPage()"></input>
        <a href ="EntryForm.html"onclick="WastePage()"> <input title="Waste Entry Page" type="wastebutton" onclick="WastePage()"></input></a>
         <a href ="EntryForm.html" onclick="MetricsPage()"> <input title="Metrics Initializer" type="gearbutton" onclick="MetricsPage()"></input></a>
         <a href="HeatMap.html"><input title="Heat Map" type="heatbutton"></input></a>
         <a href ="EntryForm.html" onclick="SafetyEntryPage()"> <input title="Safety Entry" type="safetybutton" onclick="SafetyEntryPage()"></input></a>
         <input title="Trending" type="trendbutton" onclick="Trending()"></input>
         <input title="Alarm and Events" type="alarmbutton" onclick="Alarm()"></input>
         <input title="Report Expert" type="expertbutton" onclick="ReportExpert()"></input>
         <input title="Data Entry Reports" type="ssrsbutton" onclick="DataEntrSSRS()"></input>   
      </div>
   </body>
</html>

报名表

<!DOCTYPE html>
<html>
   <head>
      <meta charset="UTF-8" content="HTML,CSS,XML,JavaScript">
       <script src="Scripts/jquery.js" type="text/javascript"></script>
      <script src="Scripts/Global.js" type="text/javascript"></script>
      <script type="text/javascript" src="Scripts/modernizr.custom.86080.js"></script>        
      <link rel="stylesheet" type="text/css" href="Styles/Design.css">
   </head>
   <body>    
       <div id="header">
         <h1 id="h1">Metrics Entry Form</h1>
         <div id="headerIcon"></div>
         <div id="tv1clock"></div>
      </div>
      <center>
      <div id="wrapper">        
            <div id="iFrameHeight">
               <iframe name="iframe" src="MetricsEntryForm.html" scrolling="auto" id="GlobalFrame"></iframe>
            </div>         
      </div>
      </center>
      <div id="footer">&nbsp;
         <a href="HomePage.html"><input title="Home Page" type="homebutton"></input></a>
         <input title="Previous Page" type="previousbutton" onclick="PreviousPage()"></input>
         <input title="Waste Entry Page" type="wastebutton" onclick="WastePage()" ></input>
         <input title="Metrics Initializer" type="gearbutton" onclick="MetricsPage()"></input>
         <a href="HeatMap.html"><input title="Heat Map" type="heatbutton"></input></a>
         <input title="Safety Entry" type="safetybutton" onclick="SafetyEntryPage()" ></input>
         <input title="Trending" type="trendbutton" onclick="Trending()"></input>
         <input title="Alarm and Events" type="alarmbutton" onclick="Alarm()"></input>
         <input title="Report Expert" type="expertbutton" onclick="ReportExpert()"></input>
         <input title="Data Entry Reports" type="ssrsbutton" onclick="DataEntrSSRS()"></input>   
      </div>
   </body>
</html>

JavaScript

function WastePage() {
    document.getElementById("h1").innerHTML = "Waste Entry Form";
    document.getElementById("GlobalFrame").src = "WasteEntryForm.html";
}
function SafetyEntryPage() {
    document.getElementById("h1").innerHTML = "Safety Entry Form";
    document.getElementById("GlobalFrame").src = "SafetyEntryForm.html";
}
function MetricsPage() {
    document.getElementById("h1").innerHTML = "Metrics Entry Form";
    document.getElementById("GlobalFrame").src = "MetricsEntryForm.html";
}

将 iframe 移动到主页并完全删除 Entry.html 页面。考虑到您要执行的操作,该页面似乎毫无价值。然后从 Waste、Metrics 和 Safety 链接中删除锚标签。这是更新后的 home.html:

  <div id="body"><br></div>
  <div id="header">
     <h1>Carrolton Plant</h1>       
     <div id="headerIcon"></div>
     <div id="tv1clock"></div>
  </div>      
  <div id="content">
    <center>
      <div id="wrapper">        
        <div id="iFrameHeight">
           <iframe name="iframe" src="MetricsEntryForm.html" scrolling="auto" id="GlobalFrame"></iframe>
        </div>         
      </div>
    </center>
   </div>
    <span id="oeeLine1GaugeContainer"></span>
    <span id="oeeLine2GaugeContainer"></span>
    <span id="oeePlantGaugeContainer"></span>
    <span id="testGaugeContainer"></span>

  <div id="footer">&nbsp;
     <input title="Home Page" type="homebutton"></input>
     <input title="Previous Page" type="previousbutton" onclick="PreviousPage()"></input>
   <input title="Waste Entry Page" type="wastebutton" onclick="WastePage()"></input>
     <input title="Metrics Initializer" type="gearbutton" onclick="MetricsPage()"></input>
     <a href="HeatMap.html"><input title="Heat Map" type="heatbutton"></input></a>
    <input title="Safety Entry" type="safetybutton" onclick="SafetyEntryPage()"></input>
     <input title="Trending" type="trendbutton" onclick="Trending()"></input>
     <input title="Alarm and Events" type="alarmbutton" onclick="Alarm()"></input>
     <input title="Report Expert" type="expertbutton" onclick="ReportExpert()"></input>
     <input title="Data Entry Reports" type="ssrsbutton" onclick="DataEntrSSRS()"></input>   
  </div>

同时将此函数添加到您的 javascript 文件中

function HomePage() {
    document.getElementById("h1").innerHTML = "Carrolton Plant";
    document.getElementById("GlobalFrame").src = "MetricsEntryForm.html";
}

无论如何我都会这样做。