【发布时间】:2011-07-06 23:26:45
【问题描述】:
我的目标是让父页面将 iframe 的 src 从空白更改为正确的 url(在给定点使用 iframe 中的 onload 处理程序,但这不是重点),然后操作 iframe 的内容.但是,当 DOM 加载时,javascript 似乎忽略了 iframe 中不在其 src 上的任何元素。有没有办法解决这个问题?
setTimeouts 旨在允许 DOM 和 iframe 加载。 编辑:修复了一些东西。 这是包含页面:
<html><head>
<script type="text/javascript">
var done = false;
var theIframe;
window.onload = function () {
setTimeout('stuff()', 2000);
clearTimeout('stuff()');
}
function stuff() {
if (!done) {
theIframe = window.myiframe;
theIframe.src = 'http://localhost/TestStuff/redirectIframe.jsp';
done = true;
stuff();
} else {
theIframe.setMe = true;
}
}
</script>
</head>
<body>
<iframe src="" width="500" height="500" id="myiframe" name="myiframe">
</iframe>
</body>
这是 iframe:
<html>
<head>
<script type="text/javascript">
var setMe = false;
window.onload = setInterval('checker()', 1000);
function checker() {
alert('hi');
if (setMe) {
window.onload = null;
top.location = 'http://www.google.com';
alert('foundit');
} else alert('a');
}
</script>
</head>
<body></body>
</html>
有什么想法吗?
【问题讨论】:
标签: javascript html iframe