Reputation: 2506
Just out of sheer curiosity, I'd like to know if there's a technique for passing things (most likely a javascript object) to external javascript within the script tag that loads that script.
<script type="text/javascript" src="example.js">
{example:'something like this'}
</script>
I'm almost certain I've seen this done somewhere once before. I find it very tidy and would like to be able to do it for libraries i'm writing so users can pass in simple options without needing to make another script.
Upvotes: 1
Views: 1570
Reputation: 205
As with what the Question Ballbin has posted says, "It should be avoided.".
But, a different way you can do it is with another script tag.
Like this:
<script>var test1 = "Testing";</script>
<script type="text/javascript" src="example.js"></script>
The example.js file should now be able to read the contents of test1.
Upvotes: 1