<script type="text/javascript" src="something.js"></script>
something.js:
var scriptTag = document.getElementsByTagName('script');
scriptTag = scriptTag[scriptTag.length - 1];
var parentTag = scriptTag.parentNode;
This was recommended in https://stackoverflow.com/a/10312824/1099074.
However this solution doesn't work in certain cirumstances.
Same can be said of https://stackoverflow.com/a/3326554/1099074.
What would be an airtight solution that doesn't involve the frownable document.write? E.g. the solution I'm currently going with:
var childId = Math.floor((Math.random() * 1000000) + 1);
document.write('<div id="' + childId + '"></div>');
var parentTag = document.getElementById(childId).parentNode;
Help greatly appreciated!