Skip to content

Instantly share code, notes, and snippets.

@teich
teich / gist:1000964
Created May 31, 2011 17:53
May 31st Heroku Updates
// 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
_XMLHttpRequest = XMLHttpRequest;
XMLHttpRequest = function () {
Object.defineProperty(this,
"__onreadystatechange",
{value: null,
writable: true,
enumerable: false});
Object.defineProperty(this,
"onreadystatechange",
@TooTallNate
TooTallNate / anotherScript.js
Created June 10, 2010 19:15
"getScriptName" is a cross-browser function to retrieve the absolute URL of the currently executing JavaScript file.
// If no exception is passed into 'getScriptName', it will only
// retrieve the URL of the script where 'getScriptName' is defined.
// In order to get the URL of a different script file, you must
// pass an exception generated in this script file to 'getScriptName'.
try {
(0)();
} catch(ex) {
getScriptName(ex, onScriptNameKnown);
}