Passing arguments to embedded Javascript

Dhanraj Acharya
wineofbits
Published in
1 min readJun 28, 2018

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, 👏👏👏.

--

--

Dhanraj Acharya
wineofbits

Full Stack Developer. I love experimenting with new tools and tech. More @ https://drex44.github.io If you can’t read any story due to the WALL then DM me @Twtr