gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 10:49:41 25 4
gpt4 key购买 nike

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

EntryForm.html 是“主表单页面”,当用户单击主页上的按钮时,需要能够更改 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 页面。考虑到您想要做什么,该页面似乎毫无值(value)。然后从“废物”、“指标”和“安全”链接中删除 anchor 标记。这是更新后的 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";
}

无论如何,这就是我会做的。

关于javascript - 引用另一个页面并更改 iframe 内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28461071/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com