Reputation: 4408
So i have iframe and i'm uploading files through it, so my question is how can i stop it in the middle of the loading? I've tried to change src with jquery function attr()
but i didn't do any good, i'm thinking of removing the whole iframe with js
but it would create me other problems and i'm not even sure if it would work. So is there some other ways to do it?
My next question would be, is it possible to hide loading indicators so it wouldn't confuse users that page is loading or something.
Answers like you should use flash or other stuff won't be accepted i already did everything with iframe i just need to do those 2 things.
Here is my iframe code:
<iframe onload="file_uploaded()" class="iframe" src="user/upload_image/" name="iframeTarget" ></iframe>
Upvotes: 16
Views: 36870
Reputation: 343
can use this for disabling all iframe content
<script>
var frames = window.frames;
var i;
for (i = 0; i < frames.length; i++) {
frames[i].location = "";
}
</script>
Upvotes: 3
Reputation: 662
This works for me (IE, Chrome, FF, Opera):
$iframe.attr('src','about:blank');
Upvotes: 9
Reputation: 6617
I believe the following answers your question: https://stackoverflow.com/a/2207589/1157493
For FireFox/Safari/Chrome you can use window.stop():
window.frames[0].stop()
For IE, you can do the same thing with document.execCommand('Stop'):
window.frames[0].document.execCommand('Stop')
For a cross-browser solution you could use:
if (navigator.appName == 'Microsoft Internet Explorer') { window.frames[0].document.execCommand('Stop'); } else { window.frames[0].stop(); }
If you'd like the iframe to go to a different page you could try to redirect it to "about:blank"
Upvotes: 23