Coder Social home page Coder Social logo

injector.js's Introduction

Injector.js

About

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).

Usage

See examples/index.html for usage.

Methods

  • 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.write calls will be captured and output will be injected either at current position.

  • Injector.insert(html) Insert HTML at current position, evaluating scripts manually and overriding document.write calls.

  • Injector.oncomplete(callback) Callback to execute after insert() or eval()

Issues

  • Calling Injector.insert() or Injector.eval() while scripts are still being inserted will cause issues.

Todo

  • Cross browser testing.

  • Convert to standalone module rather than class instance.

  • Add queue, so that insert() and eval() can be called at any time without side effects.

Thanks

Inspired and seeded from code shared by John Resig: http://ejohn.org/blog/xhtml-documentwrite-and-adsense/

injector.js's People

Contributors

joshduck avatar dustmason avatar buley avatar

Stargazers

sprite avatar Sergey Sokurenko avatar Mikkel Bergmann avatar Dudley Storey avatar  avatar Sam Spence avatar Joshua Bemman avatar Dan Zhang avatar Takis avatar steei avatar Aaria Carter-Weir avatar Damián Eiff avatar Ari Palo avatar Wenlei Zhu avatar abhilash Kamath avatar  avatar Harald Hanek avatar Yuya Takeyama avatar  avatar Mohamed Chorfa avatar Chandra Patni avatar Benjamin Fleischer avatar Sam Cooke avatar Håkan Folkesson avatar Prem Rose avatar Sindre Wimberger avatar Juan avatar  avatar Max Glenister avatar Jason Davies avatar

Watchers

 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.