Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
181
rated 0 times [  184] [ 3]  / answers: 1 / hits: 26482  / 15 Years ago, fri, february 5, 2010, 12:00:00

Is there a way in javascript of stopping an iframe in the middle of loading a page? The reason I need to do this is I have a background iframe streaming data from a web server (via a Comet style mechanism) and I need to be able to sever the connection at will.



Any ideas welcome.


More From » dom

 Answers
35

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();
}

[#97654] Tuesday, February 2, 2010, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jadyngraysons

Total Points: 455
Total Questions: 109
Total Answers: 98

Location: Trinidad and Tobago
Member since Fri, May 8, 2020
4 Years ago
jadyngraysons questions
Thu, Apr 23, 20, 00:00, 4 Years ago
Sat, Jan 18, 20, 00:00, 4 Years ago
Tue, Dec 31, 19, 00:00, 5 Years ago
;