从Iframe检索List并使用List更新父帧

Retrieving List from Iframe and updating parent frame with List

本文关键字:List 更新 Iframe 检索      更新时间:2023-09-26

我是一个noob,正试图从Iframe中检索HTML列表,并通过按下父框架中的按钮来更新父框架内的列表。请帮忙,我一直在检索一个错误"UpdateList未定义",我知道我一定做错了什么,目前我想把头撞在墙上,请求帮助

<html> 
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<style>
<script type="text/Javascript">
function UpdateList(){
var OldList = document.getElementById('Framed');
var Newlist = OldList.contentWindow;
document.getElementById('FileList').innerHTML= Newlist;}

</script>
</style>
</head>
<body style="color:white">
<div id="FileList">
<select>
<option>Push Refresh</option>
</select>
</div>
<iframe NAME="Framed" id="Framed" src="DirectoryPreview.php" width="250" height="100">
</iframe>
<br>
<button onclick="UpdateList()">Push to refresh</button>
</body>

           **Correction for the above, hope it helps others struggling**

<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<style>
</style>
<script type="text/Javascript">
function UpdateList(){
var OldList = document.getElementById('Framed');
var NewList = OldList.contentDocument || iframe.contentWindow.document;
var Contents = NewList.getElementById('List').value;
document.getElementById('FileList').innerHTML= Contents;}
</script>
</head>
<body style="color:Black">
<div id="FileList">
<select>
<option>Push Refresh</option>
</select>
</div>
<iframe NAME="Framed" id="Framed" src="DirectoryPreview.php" width="250" height="100">
</iframe>
<br>
<button onclick="UpdateList()">Push to refresh</button>
</body>
</html>

您的javascript嵌入在style tag中!!!!你怎么能指望它执行???

更改:-

<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<style>
</style> 
<script type="text/Javascript">
function UpdateList(){
var OldList = document.getElementById("Framed");
var Newlist = OldList.contentWindow;
document.getElementById("FileList").innerHTML= Newlist;
}
</script>