我想通过循环重新加载/刷新iframe,因为我有近300个iframe要重新加载/刷新
function myFrame1() {
var ifr = document.getElementsByName('frame1')[0];ifr.src = ifr.src;}
function myFrame2() {
var ifr =document.getElementsByName('frame2')[0];ifr.src = ifr.src;}
function myFrame3() {
var ifr =document.getElementsByName('frame3')[0];ifr.src = ifr.src;}
function myFrame4() {
var ifr =document.getElementsByName('frame4')[0];ifr.src = ifr.src;}
function myFrame5() {
var ifr =document.getElementsByName('frame5')[0];ifr.src = ifr.src;}
function myFrame6() {
var ifr =document.getElementsByName('frame6')[0];ifr.src = ifr.src;}
function myFrame7() {
var ifr =document.getElementsByName('frame7')[0];ifr.src = ifr.src;}
//续300个iframe。这适用于这种框架
<iframe name="frame36" src="ima/P&ID/91-120002/91-120002-02/Grp_91-120002-02.htm" alt="" class="ui-draggable ui-draggable-handle" style="display: inline-block; height: 524px; width: 720px;" border="0"></iframe>
答案 0 :(得分:1)
到目前为止,最简单的方法是使用querySelectorAll和forEach
public class NumberOperation {
public static <R extends Number & Comparable<R>> R addition(R summand1, R summand2) {
if (!summand1.getClass().equals(summand2.getClass()))
throw new IllegalArgumentException("Two different classes are used in the parameters: " + summand1.getClass().getName() + ", " + summand2.getClass().getName());
if(summand1 instanceof Double && summand2 instanceof Double)
return (R) new Double(summand1.doubleValue() + summand2.doubleValue());
else if(summand1 instanceof Float && summand2 instanceof Float)
return (R) new Float(summand1.floatValue() + summand2.floatValue());
else if(summand1 instanceof Long && summand2 instanceof Long)
return (R) new Long(summand1.longValue() + summand2.longValue());
else if(summand1 instanceof Integer && summand2 instanceof Integer)
return (R) new Integer(summand1.intValue() + summand2.intValue());
else if(summand1 instanceof Short && summand2 instanceof Short)
return (R) new Short((short) (summand1.shortValue() + summand2.shortValue()));
else if(summand1 instanceof Byte && summand2 instanceof Byte)
return (R) new Byte((byte) (summand1.byteValue() + summand2.byteValue()));
else
throw new IllegalArgumentException(summand1.getClass().getName() + " is not supported.");
}
}
用于旧浏览器支持
document.querySelectorAll('iframe').forEach(ifr => ifr.src = ifr.src);
答案 1 :(得分:0)
你可以
var iframes = document.getElementsByTagName("iframe");
或
var iframes = document.querySelectorAll('iframe');
如果您有多个iframe,请按或按名称
var iframes = document.querySelectorAll('[name^=frame]');
然后
for (i = 0 ; i < iframes.length ; i++){
iframes[i].src = iframes[i].src;
}
答案 2 :(得分:0)
您可以使用jquery,并使用它可以非常简单:
var iframe = $('iframe'), src;
iframe.each(function(index,element){
src = $(this).attr('src');
});
如果要刷新,可以使用settimeout或setinterval(长轮询)