var funcSizeRequest = function( e ) { var ref = document.createElement( 'a' ); ref.href = document.referrer; // Verify message origin if ( ref.protocol + '//' + ref.host !== e.origin ) return; // Verify message is in a format we expect if ( 'object' !== typeof e.data || undefined === e.data.msg_type ) return; switch ( e.data.msg_type ) { case 'poll_size': e.source.postMessage( { '_request' : e.data, 'msg_type' : 'poll_size:response', 'height' : document.body.scrollHeight, 'width' : document.body.scrollWidth }, e.origin ); return; default: return; } }; if ( 'function' === typeof window.addEventListener ) { window.addEventListener( 'message', funcSizeRequest, false ); } else if ( 'function' === typeof window.attachEvent ) { window.attachEvent( 'onmessage', funcSizeRequest ); }