I have a script that appends several iframes (8 as an example) into the body:
image_iframe[sequential number 1-8] = $('<iframe />');
image_iframe[sequential number 1-8].appendTo('body');
When I try to stop images in specific iframes from loading:
if(window.stop !== undefined) {
image_iframe[2].contentWindow.stop();
}
else if(document.execCommand !== undefined) {
image_iframe[2].contentDocument.execCommand("Stop", false);
}
I get the following error:
Uncaught TypeError: Cannot read property 'stop' of undefined
How can I fix this?
Here's a jsfiddle with the original code. Just click the 'Next' button a few times to reproduce the error. It is based on this jsfiddle from this question which works fine.
I did some searches and found these two questions but not sure if it's the same problem: