Here you go:
var tid = setInterval( function () {
if ( document.readyState !== 'complete' ) return;
clearInterval( tid );
// do your work
}, 100 );
Read about the document.readyState
property here. I am not sure if all current browsers implement it.