怎么能循环、顺序地从iframe中提取信息?
背景:我想在父页面中创建iframe,以从另外其它10个不同页面中不同信息。
我想到两种方法,都没走通:
1.创建一个iframe,然后循环修改iframe.src的值,但不知道为什么每次修改src都会刷新父页面?我只希望iframe内部刷新,而不刷新父页面,怎么做?
iframe.onload = function() {
iframe.setAttribute("src", someUrl);
}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);
}window.onload = function () {
var ifr = document.getElementById('iframe的ID');
ifr.src = '第一个url';
ifr.onload = function () {
nowIndex++;//
if (nowIndex < 10) {
ifr.src = ''; //根据nowIndex配置不同的url
}
}
}