【发布时间】:2013-07-22 07:18:56
【问题描述】:
我的概念是从 iframe 更新主页中文本框的值。此代码在 firefox 中有效,但在 Internet Explorer 和 Chrome 中无效。 main.html 和 frame.html 都在同一个位置。我需要建议以使其在所有浏览器中都能正常工作。
main.html
<!DOCTYPE html>
<html>
<head>
<title> main window </title>
</head>
<body>
Parent textbox :<input type="text" id="parentbox"></br></br></br>
<iframe src="frame.html" ></iframe>
</body>
</html>
frame.html
<!DOCTYPE html>
<html>
<head>
<title> frame window </title>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script>
function PushValues()
{
var frame_value = document.getElementById("framebox").value;
window.parent.document.getElementById("parentbox").value =frame_value;
}
</script>
</head>
<body>
<input type="text" id="framebox" >
<input type="button" value ="fill" onclick="PushValues()">
</body>
</html>
【问题讨论】:
-
控制台有错误吗?
-
你试过
window.top.document -
代码在 Firefox、Chrome、Safari 和 IE 中对我来说工作正常,尽管你应该关闭你的
-
@Chris 我确实有 iframe 的结束标签,我只是在这里错过了它。你能告诉我你的浏览器版本吗?
-
@Cherniv 我在 Chrome 控制台中收到以下错误。 1.
Blocked a frame with origin "null" from accessing a frame with origin "null".2.Protocols, domains, and ports must match. Uncaught TypeError: Cannot call method 'getElementById' of undefined .
标签: javascript jquery html iframe