You cannot discover this in a simple way. You can try to listen to the load event on the iframe and set a timeout, and if the timeout fires, block the iframe because the iframe did not load like this ( jsfiddle example ):
checkMixedContent(urlToCheck, function(urlToCheck) {
alert('ok');
}, function() {
alert('Error: resource timed out');
}, checkDelay);
function checkMixedContent(urlToCheck, successCallback, errorCallback, checkDelay, dontCheckOnError) {
checkDelay = checkDelay || 10000;
var iframeHelper = document.createElement("iframe");
iframeHelper.src = urlToCheck;
iframeHelper.height = 0;
iframeHelper.width = 0;
iframeHelper.style.visibility = 'hidden';
document.body.appendChild(iframeHelper);
var checkTimeout = window.setTimeout(function() {
errorCallback(urlToCheck);
}, checkDelay);
var onLoad = function() {
window.clearTimeout(checkTimeout);
iframeHelper.removeEventListener('load', onLoad);
iframeHelper.removeEventListener('error', onError);
document.body.removeChild(iframeHelper);
successCallback(urlToCheck);
};
var onError = function() {
window.clearTimeout(checkTimeout);
iframeHelper.removeEventListener('load', onLoad);
iframeHelper.removeEventListener('error', onError);
document.body.removeChild(iframeHelper);
errorCallback(urlToCheck);
};
iframeHelper.addEventListener('load', onLoad);
if (!dontCheckOnError) {
iframeHelper.addEventListener('error', onError);
}
}
source
share