从具有相同父级的单独 iFrame 更改 iFrame 源
Change iFrame Source from separate iFrame with same parent?
这是我完整的最新代码,它不起作用。这是主窗口 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>
这是 menus/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>
每当我按下菜单框架上的按钮时,身体框架都不会改变。
确保在简单的服务器上运行并进行测试。许多浏览器在 iframe 方面都有限制。
如果使用 file://协议,许多文件无法正常工作,如果您直接打开 html 文件(即:不通过服务器),则会使用该协议。
你拼错了getElementById
:最后一个字母d
不应该是大写的。
而不是window.document.getElementById
你可以写document.getElementById
,因为window
是浏览器javascript中的全局对象(至少,每个窗口/(i)帧的全局对象)
http://jsfiddle.net/kNrVL/
相关文章:
- 防止Iframe窗体在新窗口中打开
- 将样式表插入iframe
- 在单独的ul's
- Javascript排序的图像弹出窗口..可以't单独弹出
- 为什么在单独的函数中应用时转换会闪烁/断断续续(D3)
- 在Twitter上用ie9中的空白src访问iframe的contentWindow
- 使用jQuery从原始页面内容创建iframe
- Highslide(iframe的侦听器)
- iframe正在添加标签,需要删除它们
- 通过javascript/html访问twitter共享iframe
- 如何在Facebook上的iframe应用程序中使后退按钮返回到上一页
- 如何使用Angular动态添加iframe-src
- 由于iframe导致的问题
- 浏览器会为iframe提供一个单独的JavaScript线程吗
- 单独用于 iframe 的“后退”按钮
- 将 PHP 联系表单加载到位于单独 HTML 页面上的 Iframe 中
- 从具有相同父级的单独 iFrame 更改 iFrame 源
- 为同源CPU密集型iframe单独的事件循环
- 从单独的 iframe 中的.php刷新 iframe
- 使用文本区域在 iframe 中显示实时结果,使用 jQuery,将单独的文本区域输入添加到 iframe 头中