cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <h1>Dynamic javascript Document creation</h1>

<h2>Parsed title: <span id="title"></span></h2>

<iframe id="iframe"></iframe>

            
          
!
            
              h1, h2 {
  text-align: right;
}

iframe {
  position: absolute;
  height: 100%;
  width: 100%;
  padding: 0;
  border: 0;
  margin: 0;
  left: 0;
  top: 0;
}

            
          
!
            
              doc2html = (doc) ->
  (new XMLSerializer).serializeToString doc

text2html = (t) ->
  t.replace(/&/g, '&amp;').replace(/</g, '&lt;')

doc = document

# show our own source, in the bg iframe document
html = doc2html doc

show = doc.getElementById 'title'
frame = doc.getElementById 'iframe'

# create a new empty document (without a title)
src = doc.implementation.createHTMLDocument ''

# copy the current document's contents to it
src.open()
src.write html
src.close()
# read out the page's title:
show.textContent = src.title

# repeat, but this time show the page's source:
html = text2html html
src.open()
src.write "<!DOCTYPE><html><pre>#{html}</pre></html>"
src.close()

# show our new doc in our background iframe:

copyDoc = (src, dst) ->
  src_root = src.documentElement
  new_root = dst.importNode src_root, true
  dst.replaceChild new_root, dst.documentElement

copyDoc src, frame.contentDocument

            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console