如何在for循环中更改iframes或window.opener.location的src
How to change the src of iframes or window.opener.location in a for loop?
我想更改iframe的src属性或for循环中的window.opener.location。例如:
- 启动循环
- 将src从iframe更改为link1
- 等待1秒
- 下一个
- 将src从iframe更改为link2
- 等待1秒
- 下一个
- […]
- 结束循环
然而,每当我试图在这样的for循环中实现它时:
iframe = document.createElement('iframe');
document.body.appendChild(iframe);
iframe.src = 'http://example.com/index.php?x=init';
for(i = 1; i <= 5; i++)
{
console.log(i)
iframe.src = 'http://example.com/index.php?x='+i;
sleep(1000) // <- A sleep function that does a while loop for 1000 ms
}
在实际打印iframe之前,它总是在控制台中打印1,2,3,4,5,然后只将其src更改为最后一个。
我做错了什么吗?有可能用javascript实现这样的功能吗?还是我必须采取不同的做法?我对for循环和window.opener.location.
如果你想你想要的是这样的东西。
iframe = document.createElement('iframe');
document.body.appendChild(iframe);
iframe.src = 'http://example.com/index.php?x=init';
var i = 0;
var interval = setInterval(function() {
i++;
console.log(i)
iframe.src = 'http://example.com/index.php?x='+i;
if (i === 5) {
clearInterval(interval);
}
}, 1000);
相关文章:
- window.opener.document在ie中不起作用
- 通过window.opener将弹出窗口中的值传递给父窗口
- 检测window.opener窗口刷新事件
- Form.target=window.opener.name不起作用
- window.opener not working in chrome & IE
- 跨原点-弹出窗口(window.opener为空)
- window.opener引用在Java 1.7.0_04-b20中从Applet重定向期间发生了更改,但在1.7.0_
- window.opener调用函数给了我一个文档.getElementById(..)为null
- Window.opener 未定义在 IE8 中
- window.opener.dispatchEvent 不会在 Firefox 中传输附加的数据
- 为什么
- 受信任站点 WinXP IE 8 的错误“window.opener.top 为空或不是对象”
- 如何允许 Window.opener.location.href 权限 对于 Greasemonkey
- 无法将值从 window.opener 传递到其父级
- Soundcloud Javascript API - Connect window.opener.setTimeout
- Javascript :使用window.opener表单弹出窗口将字符串添加到iframe
- 这里有一种新型的广告javascript通过change"window.opener.location”;,我
- window.opener is null in firefox
- 我该如何检查我是否可以访问window.opener
- window.opener.close() is not working