Skip to content

Instantly share code, notes, and snippets.

@jamc92
Created February 22, 2015 17:06
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 jamc92/7cd69294e2af5cab2867 to your computer and use it in GitHub Desktop.
Save jamc92/7cd69294e2af5cab2867 to your computer and use it in GitHub Desktop.
JS - Send an argument to an js function from <script src=""> tag
<!DOCTYPE html>
<html>
<head>
<title>Arguments Demo</title>
<script src="arguments.js" spinner="spinner.png"></script>
</head>
<body>
</body>
</html>
if(!NSArguments) {
var Arguments = function() {
var self = {
script: document.currentScript || document.scripts[document.scripts.length-1]
};
var that = {};
that.getArgument = function(name) {
return self.script.getAttribute(name);
};
return that;
};
var NSArguments = Arguments();
}
(function(){
window.addEventListener("load", function() {
var spinner = NSArguments.getArgument("spinner");
console.log(spinner);
});
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment