Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 是否从具有相同父级的单独iFrame更改iFrame源?_Javascript_Html_Button_Iframe - Fatal编程技术网

Javascript 是否从具有相同父级的单独iFrame更改iFrame源?

Javascript 是否从具有相同父级的单独iFrame更改iFrame源?,javascript,html,button,iframe,Javascript,Html,Button,Iframe,这是我完整的最新代码,它不起作用。这是HTML的主窗口 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Ty

这是我完整的最新代码,它不起作用。这是HTML的主窗口

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Website</title>
<link rel="stylesheet" type="text/css" href="css/main.css" />
</head>

<body background="core_rec/web_res/cf2.jpg">
<center>
<table width="720" cellpadding="0" cellspacing="0" border="0">
<tr>
<td width="180"><img src="core_rec/logos/metaltop.png" /></td>
<td colspan="3"><img src="core_rec/web_res/title.png" align="bottom"/></td>
</tr>
<tr>
<td width="180"><img src="core_rec/logos/metalbottom.png" /></td>
<td width="70"><center><font id="menutext">Menu</font></center></td>
<td width="100"><center><font id="menutext">Info</font></center></td>
<td width="200"><center><font id="menutext">Products/Services</font></center></td>
<td width="170"><center><font id="menutext">Contact</font></center></td>
</tr>
</table>
<br /><br />
<table height="80%" width="720">
<tr>
<td width="140"><iframe src="iframes/menus/main.html" width="140" id="sidebar"></iframe></td>
<td width="540"><iframe src="iframes/bodies/main/main.html" width="540" name="bodyframe" id="bodyframe"></iframe></td>
</tr>
</table>
</center>
</html>
这是菜单/main.html。它包含按钮

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>iFrame Main</title>
<link rel="stylesheet" type="text/css" href="../../css/main.css" />
</script>
</head>

<body bgcolor="#000000">
<center>
<font id="sidebartext">
Main<br /><br />
Other Feeds<br /><br />
<button onclick="parent.document.getElementById('bodyframe').src='../bodies/main/othersites.html'">Other Sites</button><br /><br />
</font>
</center>
</body>
</html>
每当我按下菜单框上的按钮时,正文框不会改变。

您拼写错误了getElementById:最后一个字母d不应该是大写

您可以编写document.getElementById来代替window.document.getElementById,因为window是浏览器javascript中的全局对象,至少是每个窗口/iframe的全局对象


确保在一个简单的服务器上运行并进行测试。对于iFrame,许多浏览器都有限制


如果使用file://协议,许多文件无法正常工作,如果您直接打开html文件,即:不通过服务器打开,将使用该协议。

发布您的完整膨胀代码,以便我可以修复。。只需尝试使用top.document.getElementById一次,如果无法工作,top.window.document.getElementByIDI如果您使用chrome,请确保检查javascript控制台是否存在由于安全原因而导致的错误。它非常严格。file://protocol有很多东西是不允许的,所以在服务器onceWow上尝试同样的方法。我昨晚一定累了。我看了这些代码,不知道为什么要写这个窗口。我用更好的代码编辑了我的文章,这就是我最初的意思。从哪个角度设置源路径?从目标iframe,从父窗口,或从iframe按钮打开?啊。让我把它扔到服务器上检查一下。很高兴知道。新浏览器有许多意想不到的安全功能,会阻止很多活动,所以如果出现问题,请小心。是的,谢谢。现在我知道,如果某个东西不起作用,就先上传它,然后再对它感到沮丧。