Passing arguments to embedded Javascript
So, you’re writing an embedded script and you want to pass some arbitrary arguments and parameters to your javascript. How do you do it? This quick little tutorial will show you an example.
This is the easiest method. HTML5 now supports arbitrary parameters, so you can pass any arguments to your function with that.
Tutorial
So, your embed script tag will look like this:
<script id="index_js" redirectUrl="/tnc.html"
src="http://domain.com/index.js" >
Then, inside your javascript:
var script_tag = document.getElementById('index_js');
var redirectUrl = script_tag.getAttribute("redirectUrl");
And that’s it! Easy peasy.
The downside of this is that some very very old browsers might not like your arbitrary HTML5 attributes.
Conclusion
And that’s it! Did this work for you? Please leave any questions and comments below!
Thank you for reading!
If you found this article helpful, 👏👏👏.