You can use the readystate iframe property to check if the iframe is fully loaded. However, this does not work in Chrome if the content is a binary.
Once the iframe url is set, it checks the readramate iframe property every second:
$("#test").click(function(){ iframe = document.getElementById("download-container1"); if (iframe === null) { $("#ajax_loading").show(); var url="http://test.coachfxlive.com/ajax/ajax-action.php?type=s&vid=0&playlist_id=11&perpage=1&action=get_profile"; iframe = document.createElement('iframe'); iframe.id = "download-container1"; document.body.appendChild(iframe); //$('#download-container1').load(function () { // $("#ajax_loading").hide(); //}); iframe.src=url; checkFinishedDownload(iframe); } }); function checkFinishedDownload(ifr) { if (ifr.readyState == "complete" || ifr.readyState == "interactive") { // Here hide the spinner $("#ajax_loading").hide(); } else { setTimeout(function () { checkFinishedDownload(ifr); }, 1000); } } }
Check my question: Iframe.readyState not working in chrome
EDIT: In firefox, you can use the onload :
function checkFinishedDownload(ifr) { if ($.browser.mozilla) { ifr.onload = function () { $("#ajax_loading").hide(); } }else{ iframeCheck(ifr); } } function iframeCheck(iframe){ if (iframe.readyState == "complete" || iframe.readyState == "interactive") {
source share