Created
January 26, 2015 18:16
-
-
Save JamesMGreene/28b188e56c7f72d002fb to your computer and use it in GitHub Desktop.
Less error-prone version of https://developer.mozilla.org/samples/html/currentScript.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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