Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop iframe from loading

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>
like image 549
Linas Avatar asked Dec 28 '25 19:12

Linas


1 Answers

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"

like image 86
Rick Kuipers Avatar answered Dec 30 '25 09:12

Rick Kuipers



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!