Skip to content

Instantly share code, notes, and snippets.

@micahwave
Created November 7, 2014 22:18
Show Gist options
  • Save micahwave/9e13f4b5de60e47d4440 to your computer and use it in GitHub Desktop.
Save micahwave/9e13f4b5de60e47d4440 to your computer and use it in GitHub Desktop.
Example protected iframe markup
<form id="wpcom-iframe-form-d0dd6dc80896d44e1f92797eb842b978-545d44c092acf" target="wpcom-iframe-d0dd6dc80896d44e1f92797eb842b978-545d44c092acf" method="post" action="//wpcomwidgets.com/?wpcom_origin=http%3A%2F%2Fqzstage.wordpress.com" style="display: none"><input type="hidden" name="frameborder" value="0" /><input type="hidden" name="scrolling" value="no" /><input type="hidden" name="resize" value="0" /><input type="hidden" name="replace_attributes" value="1" /><input type="hidden" name="fallback" value="&lt;p class=&quot;protected-embed-fallback&quot;&gt;&lt;a href=&quot;http://www.bloomberg.com/video/embed/pYrwEuk2T9~xmXMYD3o6fg?height=395&amp;width=640&quot;&gt;http://www.bloomberg.com/video/embed/pYrwEuk2T9~xmXMYD3o6fg?height=395&amp;width=640&lt;/a&gt;&lt;/p&gt;" /><input type="hidden" name="class" value="" /><input type="hidden" name="width" value="640" /><input type="hidden" name="height" value="430" /><input type="hidden" name="style" value="overflow:hidden;" /><input type="hidden" name="_data" value="PG9iamVjdCBkYXRhPSdodHRwOi8vd3d3LmJsb29tYmVyZy5jb20vdmlkZW8vZW1iZWQvcFlyd0V1azJUOX54bVhNWUQzbzZmZz9oZWlnaHQ9Mzk1JndpZHRoPTY0MCcgd2lkdGg9NjQwIGhlaWdodD00MzAgc3R5bGU9J292ZXJmbG93OmhpZGRlbjsnPjwvb2JqZWN0Pg==,47423558026f00fb6e94e23e92f369c7fecc21db" /><input type="hidden" name="_tag" value="protected-iframe" /><input type="hidden" name="_hash" value="d0dd6dc80896d44e1f92797eb842b978" /></form><iframe name="wpcom-iframe-d0dd6dc80896d44e1f92797eb842b978-545d44c092acf" id="wpcom-iframe-d0dd6dc80896d44e1f92797eb842b978-545d44c092acf" width="640" height="430" frameborder="0" scrolling="no" class="wpcom-protected-iframe "></iframe><script type="text/javascript">( function() {var func = function() {var iframe_form = document.getElementById('wpcom-iframe-form-d0dd6dc80896d44e1f92797eb842b978-545d44c092acf');var iframe = document.getElementById('wpcom-iframe-d0dd6dc80896d44e1f92797eb842b978-545d44c092acf');if ( iframe_form && iframe ) {iframe_form.submit();iframe.onload = function() {iframe.contentWindow.postMessage( {'msg_type': 'poll_size','frame_id': 'wpcom-iframe-d0dd6dc80896d44e1f92797eb842b978-545d44c092acf'}, window.location.protocol + '//wpcomwidgets.com' );}}// Autosize iframevar funcSizeResponse = function( e ) {var origin = document.createElement( 'a' );origin.href = e.origin;// Verify message originif ( 'wpcomwidgets.com' !== origin.host )return;// Verify message is in a format we expectif ( 'object' !== typeof e.data || undefined === e.data.msg_type )return;switch ( e.data.msg_type ) {case 'poll_size:response':var iframe = document.getElementById( e.data._request.frame_id );if ( iframe && '' === iframe.width )iframe.width = '100%';if ( iframe && '' === iframe.height )iframe.height = parseInt( e.data.height );return;default:return;}}if ( 'function' === typeof window.addEventListener ) {window.addEventListener( 'message', funcSizeResponse, false );} else if ( 'function' === typeof window.attachEvent ) {window.attachEvent( 'onmessage', funcSizeResponse );}}if (document.readyState === 'complete') { func.apply(); /* compat for infinite scroll */ }else if ( document.addEventListener ) { document.addEventListener( 'DOMContentLoaded', func, false ); }else if ( document.attachEvent ) { document.attachEvent( 'onreadystatechange', func ); }} )();</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment