Injector.js is a helper library to ease the pain of mixing asynchronous
JavaScript and dynamic content building with third party scripts which insist
document.write is still a good idea.
This script in beta but works on major browsers (IE, Firefox and Chome).
See examples/index.html for usage.
-
Injector(options)Constructor. -
Injector.setContainer(element)Set the parent container that HTML should be injected into. Can also be set via options.container. -
Injector.setSibling(element)Set the node which HTML should be injected before. Can also be set via options.sibling. -
Injector.eval(script)Evaluate inline script,document.writecalls will be captured and output will be injected either at current position. -
Injector.insert(html)Insert HTML at current position, evaluating scripts manually and overridingdocument.writecalls. -
Injector.oncomplete(callback)Callback to execute afterinsert()oreval()
- Calling
Injector.insert()orInjector.eval()while scripts are still being inserted will cause issues.
-
Cross browser testing.
-
Convert to standalone module rather than class instance.
-
Add queue, so that
insert()andeval()can be called at any time without side effects.
Inspired and seeded from code shared by John Resig: http://ejohn.org/blog/xhtml-documentwrite-and-adsense/