Javascript 在iframe中打开本地页面
我有两个iFrame,我需要点击按钮(在我的顶部框架)加载另一个本地页面(help_content.html)(到我的底部框架)。topframe有一个表单(help_form.html),其中有3个按钮(2个有效),而bottomframe当前是一个blank.html,需要在单击按钮时加载help_screen.html help\u screen.HTML中的HTMLJavascript 在iframe中打开本地页面,javascript,html,iframe,Javascript,Html,Iframe,我有两个iFrame,我需要点击按钮(在我的顶部框架)加载另一个本地页面(help_content.html)(到我的底部框架)。topframe有一个表单(help_form.html),其中有3个按钮(2个有效),而bottomframe当前是一个blank.html,需要在单击按钮时加载help_screen.html help\u screen.HTML中的HTML <iframe name="topframe" id="topframe" src="help_form.html"
<iframe name="topframe" id="topframe" src="help_form.html"><p>Your browser cannot view iFrames</p></iframe>
<br/>
<iframe name="bottomframe" id="bottomframe" src="blank.html"><p>Your browser cannot view iFrames</p></iframe>
<input type="button" name="help1" value="Click for help" onclick="openHelp()" />
help\u form.HTML上按钮的HTML
<iframe name="topframe" id="topframe" src="help_form.html"><p>Your browser cannot view iFrames</p></iframe>
<br/>
<iframe name="bottomframe" id="bottomframe" src="blank.html"><p>Your browser cannot view iFrames</p></iframe>
<input type="button" name="help1" value="Click for help" onclick="openHelp()" />
在javascript中,您已将
src
设置为help\u screen.html
而您应该将其设置为
help\u content.html
编辑
help_screen.html必须包含以下代码:
<!DOCTYPE html>
<html>
<head>
<script>
function openHelp() {
var frame = document.getElementById("bottomframe");
frame.setAttribute("src", "help_content.html");
}
</script>
</head>
<body>
<iframe name="topframe" id="topframe" src="help_form.html">Your browser suckss...</iframe>
<iframe name="bottomframe" id="bottomframe" src="#">Your browser really suckss...</iframe>
</body>
</html>
函数openHelp(){
var frame=document.getElementById(“底部框架”);
setAttribute(“src”、“help_content.html”);
}
你的浏览器糟透了。。。
你的浏览器真的很烂。。。
您的help_form.html必须包含以下按钮:
<input type="button" onclick="parent.window.openHelp()">
您不需要调用父对象的
窗口
字段,只需直接从该字段调用函数即可,因为父对象
已经是对窗口的引用:
onclick="parent.openHelp();"
正如建议的那样(引用):
……看到了吗
返回对当前窗口或子帧的父级的引用
如果窗口没有父对象,则其父对象属性为引用
自言自语
将窗口加载到或其
父窗口是包含嵌入窗口的元素的窗口
前提是该函数是在help\u screen.html
上定义的
但是,如果您的函数是在子函数上定义的,则应该像这样调用它():
或:
我通过使用函数openHelp(document){parent.document.getElementById('bottomframe').src=“help\u content.html”使它工作起来;
}
虽然它不会在Chrome上工作,但我很高兴它能工作。
非常感谢@Aditya和@arielnmz的帮助。非常感谢。谢谢您的回复。我刚刚尝试了所有的组合,但不幸的是它仍然不起作用。谢谢,但它仍然不起作用。我的目录如下。。。order_form.html(主页上有一个打开help_screen.html的按钮)help_screen.html(包含iframes-topframe和bottomframe)help_form.html(填充iframe(topframe)并有一个单击按钮用help_content.html填充bottomframe)help_content.html(是我要填充bottomframe的页面)blank_page.html(是bottomframe的当前页面)我认为您可能在正确的轨道上,但可能在大量页面中遗漏了一步。目的是打开一个窗口,当在顶部框架上单击按钮时,它打开下面的“帮助”,给出填写上面表格的说明。@aingelic您能告诉我您将javascript代码片段放在哪个文件中吗?你的
help\u screen.html
是在单独的选项卡上打开的,还是在同一个选项卡上打开的,还是在iframe中打开的?我有一个名为music.js的javascript文件,它链接到我的html页面谢谢你。我刚刚尝试了你的所有建议,但仍然没有运气让它显示出来。javascript代码定义在哪里?如果你发出警报('hola')代码>就在函数的开头,你真的看到了警报吗?是的,只要点击按钮,警报(document.getElementById(“bottomFrame”)的输出就会弹出警报代码>?当它弹出时表示为空
parent.document.bottomFrame.contentWindow.openHelp();