Skip to content

Instantly share code, notes, and snippets.

@jugglinmike
Created June 4, 2012 14:37

Revisions

  1. jugglinmike created this gist Jun 4, 2012.
    7 changes: 7 additions & 0 deletions scoped.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    <div class="container">
    <style scoped>
    p { color: red; }
    </style>
    <p>This paragraph has red text.<p>
    </div>
    <p>This paragraph does not.</p>
    16 changes: 16 additions & 0 deletions wrap.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    function wrapInIframe( iframe, content ) {
    var win = iframe.contentWindow;
    var doc;

    if (!win) {
    throw("Failed to wrap content in iFrame: \
    please ensure the target iFrame is appended \
    to the document before writing");
    }

    doc = win.document;

    doc.open();
    doc.write(content);
    doc.close();
    }