JSFiddle - React, Tailwind, and code Playground
HTML
<button id="next">Next</button><br><br>
JavaScript
$('#next').click(function(){
nextImage();
});
function preload(arrayOfImages) {
$(arrayOfImages).each(function(){
if (image_iframe[this] == null) {
// append iframes into body with the images
image_iframe[this] = $('<iframe />');
image_iframe[this].appendTo('body');
image_tag[this] = $('<img src="'+ image_url[this] +'"/>');
image_tag[this].appendTo(image_iframe[this].contents().find('body'));
}
if (this > 4) {
// stop old iframes from loading
if(window.stop !== undefined) {
image_iframe[this - 3].get(0).contentWindow.stop(); // HERE'S THE ERROR
console.log(image_url[this] + " stopped");
}
else if(document.execCommand !== undefined) {
image_iframe[this - 3].get(0).contentDocument.execCommand("Stop", false);
}
}
});
}
var image_iframe = [];
var image_url = [];
var image_tag = [];
// example images
image_url[1] = 'http://www.jaavuu.com/content/1/slides/jaavuu-one-event-one-gallery.jpg';
image_url[2] = 'http://i.imgur.com/38rsn6h.gif';
image_url[3] = 'http://upload.wikimedia.org/wikipedia/commons/e/e0/20060731001950_-_%E7%BA%B3%E8%B5%A4%E5%8F%B0%E7%AB%99.gif';
image_url[4] = 'http://upload.wikimedia.org/wikipedia/commons/3/3f/20060416104508_-_%E5%8C%97%E4%BA%AC%E5%9C%B0%E9%93%8113%E5%8F%B7%E7%BA%BF%E4%BA%94%E9%81%93%E5%8F%A3%E7%AB%99.gif';
image_url[5] = 'http://upload.wikimedia.org/wikipedia/commons/5/56/20060416104810_-_%E5%8C%97%E4%BA%AC%E5%9C%B0%E9%93%8113%E5%8F%B7%E7%BA%BF%E5%A4%A7%E9%92%9F%E5%AF%BA%E7%AB%99.gif';
image_url[6] = 'https://lh5.googleusercontent.com/-J9nOy1ypilw/TmtQcZTMEbI/AAAAAAAAD1A/6vOhaQw5P9o/s781/Verre02_Micael_Reynaud_800_p0.gif';
image_url[7] = 'https://lh5.googleusercontent.com/-mvpIxrtlkAA/Tndmi1sf6zI/AAAAAAAAD1E/I2vwpRqn1z8/s500/FlyEarth500_Micael_Reynaud.gif';
image_url[8] =...