Created
February 22, 2015 17:06
-
-
Save jamc92/7cd69294e2af5cab2867 to your computer and use it in GitHub Desktop.
JS - Send an argument to an js function from <script src=""> tag
This file contains 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>Arguments Demo</title> | |
<script src="arguments.js" spinner="spinner.png"></script> | |
</head> | |
<body> | |
</body> | |
</html> |
This file contains 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
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