背景:我想在父页面中创建iframe,以从另外其它10个不同页面中不同信息。我想到两种方法,都没走通:
1.创建一个iframe,然后循环修改iframe.src的值,但不知道为什么每次修改src都会刷新父页面?我只希望iframe内部刷新,而不刷新父页面,怎么做?
iframe.onload = function() {
iframe.setAttribute("src", someUrl);
}2.每次循环先创建一个iframe,然后把数据传给父页面,最后删掉iframe。这样的问题是传数据不是顺序进行的,我希望第一个页面的数据传完后删掉iframe,然后再创建第二个页面的iframe再传数据。而现在10个页面的传输数据我无法用for循环控制,怎么能强制一个iframe传完数据后再进行下一个循环呢?
for(var userIndex=1; userIndex<10; userIndex++) {
iframe.onload = function() {
iframe.setAttribute("src", document.getElementsByClassName("photo_wrap")[userIndex].getElementsByTagName("a")[1].getAttribute("href"));
}
chrome.extension.onMessage.addListener(function(data) {
var newHeader = document.createElement("h4");
txt = document.createTextNode(data);
newHeader.appendChild(txt);
content.appendChild(newHeader);
});
iframe.onload = function() {
iframe.parentNode.removeChild(iframe);
}
1.创建一个iframe,然后循环修改iframe.src的值,但不知道为什么每次修改src都会刷新父页面?我只希望iframe内部刷新,而不刷新父页面,怎么做?
iframe.onload = function() {
iframe.setAttribute("src", someUrl);
}2.每次循环先创建一个iframe,然后把数据传给父页面,最后删掉iframe。这样的问题是传数据不是顺序进行的,我希望第一个页面的数据传完后删掉iframe,然后再创建第二个页面的iframe再传数据。而现在10个页面的传输数据我无法用for循环控制,怎么能强制一个iframe传完数据后再进行下一个循环呢?
for(var userIndex=1; userIndex<10; userIndex++) {
iframe.onload = function() {
iframe.setAttribute("src", document.getElementsByClassName("photo_wrap")[userIndex].getElementsByTagName("a")[1].getAttribute("href"));
}
chrome.extension.onMessage.addListener(function(data) {
var newHeader = document.createElement("h4");
txt = document.createTextNode(data);
newHeader.appendChild(txt);
content.appendChild(newHeader);
});
iframe.onload = function() {
iframe.parentNode.removeChild(iframe);
}
解决方案 »
- JS选项卡切换功能
- checkbox怎样显示数据库中指定的内容
- 到底history.back()做了什么?
- window.location.hash在IE和firefox中的区别?
- 求救,怎么利用JS在编辑器里面在任何模式下都取得代码模式的长度
- iframe里的网页,怎么实现控制他的parent网页的滚动条的位置,好像“parent.scrollTop=200”不行
- select用js怎么循环的 我的老是报错呀!!
- 怎么才能知道客户端office版本?
- 这样的C#代码如何改成javascript的?
- 这个效果如何实现,还有没有高手????
- 急:匹配正则表达式
- alert提示后如何阻止页面的跳转
我是这么做的,但是它好像会刷新父页面,我没有做其它设置啊...另外,setinterval只能基于时间吧,我希望能基于事件,就是一加载完传完数据就刷新。
$("iframe的ID").attr("src",someUrl);基于事件就要你自己加判断了
var nowIndex=1;
window.onload = function () {
var ifr = document.getElementById('iframe的ID');
ifr.src = '第一个url';
ifr.onload = function () {
nowIndex++;//
if (nowIndex < 10) {
ifr.src = ''; //根据nowIndex配置不同的url
}
}
}
通过在父页面上设置变量控制子页面刷新的次数,有效!
问题解决,谢谢。
想多问一句:因为我看到浏览器上的刷新按钮有在转,其实它只是刷新了iframe里的页面是吗?
iframe加载进度条也会动的