Skip to content

Instantly share code, notes, and snippets.

@JamesMGreene
Created January 26, 2015 18:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JamesMGreene/28b188e56c7f72d002fb to your computer and use it in GitHub Desktop.
Save JamesMGreene/28b188e56c7f72d002fb to your computer and use it in GitHub Desktop.
<!doctype html>
<html>
<head>
<title>currentScript Example</title>
<script type="text/javascript" id="mainscript" async>
if (document.currentScript && document.currentScript.async) {
console.log("Executing asynchronously");
} else {
console.log("Executing synchronously (?)");
}
function logMessage(m) {
var theList = document.getElementById("output");
if (theList) {
var newItem = document.createElement("li");
newItem.innerHTML = m;
theList.appendChild(newItem);
}
}
function starting(e) {
logMessage("Starting script with ID: " + e.target.id);
}
function finished(e) {
logMessage("Finished script with ID: " + e.target.id);
}
document.addEventListener("beforescriptexecute", starting, true);
document.addEventListener("afterscriptexecute", finished, true);
</script>
</head>
<body>
<p>Demonstration of <code>beforescriptexecute</code> and
<code>afterscriptexecute</code>.</p>
<h3>Output</h3>
<ul id="output">
</ul>
</body>
<script type="text/javascript" id="somescript">
console.log("Look, I'm a script!");
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment