I'm trying to load a zoom.it script dynamically, but I can't seem to do so without document.write
. The problem with document.write
is that it replaces everything on my page, which I don't want. What other alternatives are there?
This is document.write
in action: http://jsfiddle.net/JyT9B/6/ (notice the element that gets removed).
Also, putting the <script>
tag straight into the body works: http://jsfiddle.net/gTcRw/5/, but I need it to be dynamically placed.
I've also tried the methods in Ways to add javascript files dynamically in a page, and How to add and remove js files dynamically, but seem to get the error Cannot set property 'innerHTML' of null
, which is probably a zoom.it specific thing. I wouldn't mind knowing why this is the case.
The jsfiddle examples of using the other approaches:
- $('body').append
- $.getScript
- document.createElement as per google analytics
- document.createElement in a function
Also tried this in vain: .innerHTML - it gets added to the dom but isn't run.