Skip to content

Instantly share code, notes, and snippets.

@tlrobinson
Created March 3, 2011 21:41
Show Gist options
  • Save tlrobinson/853658 to your computer and use it in GitHub Desktop.
Save tlrobinson/853658 to your computer and use it in GitHub Desktop.
// Injecting JavaScript
// Basic compact
document.body.appendChild(document.createElement("script")).src="foo.js"
// Function wrapped
(function(d){d.body.appendChild(d.createElement("script")).src="foo.js"})(document)
// With "with"
with(document){body.appendChild(createElement("script")).src="foo.js"}
// Injecting CSS
// Basic compact (leaks a global)
l=document.createElement("link");l.rel="stylesheet";l.href="foo.css";document.body.appendChild(l)
// Function wrapped
(function(d,l){l=d.createElement("link");l.rel="stylesheet";l.href="foo.css";d.body.appendChild(l)})(document)
// With "with"
with(document){with(body.appendChild(createElement("link"))){rel="stylesheet";href="foo.css"}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment