This is probably not possible but worth asking. I am dynamically inserting script tags into my head
section of my page. At the moment I am using document.write
which many of you will frown upon, but it does do the job fine.
However, for the reasons outlined here, I would like to find an alternative to document.write
.
Therefore, I need a function that will do this:
<!-- The document.write writes the new script here synchronously so it will block other scripts -->
<script type="text/javascript">
// Code here that uses the code from the dynamically inserted script
</script>
Can anybody suggest anything with jQuery or plain javascript that will insert an element on the page, but also meets these requirements:
- Places the element at the point of which the function was called. e.g. the script tag gets placed after the script tag that called it
- The script gets loaded synchronously and therefore blocks the other scripts until it is complete
Google do this with their Google.load()
method, do they use document.write? Surely not...