Check if iframe is loaded correctly

Date: 2017-02-01
function isFrameLoaded(frame) {
    // Get a handle to the iframe element
    var frameDoc = frame.contentDocument || frame.contentWindow.document;
    // Check if loading is complete
    return !!(frameDoc && frameDoc.readyState == 'complete');
}
	
document.addEventListener('DOMContentLoaded', function() {
    var targetUrl = 'http://localhost:8080/';
	setInterval(function() {
	    var frame = document.getElementById('iframeID');
	    var frameSrc = frame.getAttribute('src');
	    if (('' + frameSrc).indexOf(targetUrl) < 0 || !isFrameLoaded(frame)) {
	        frame.setAttribute('src', targetUrl + '?_=' + Math.random());
	    }		
	}, 6000);
	
}, false);
	
6000cookie-checkCheck if iframe is loaded correctly