Git Product home page Git Product logo

smallpox's Introduction

Overview

Smallpox is a quick hack to emulate document.write and capture the output inside an arbitrary DOM node.

This allows asynchronous loading of legacy JavaScript code, as well as usage in XHTML documents, which do not support document.write.

Approach

Smallpox overrides the document.write method, gathering the output in a buffer and then appending it to the innerHTML property of the DOM node. Before that, the output is processed with a minimal parser to allow inclusion in an XHTML document.

Usage

Include the script and call the smallpox function as follows:

smallpox(id, url, done)
  • id: The ID of the element to capture the output in.
  • url: The URL of the script to include.
  • done: An optional function to be called when the script has finished.

Example

The following code shows how to use Google Adsense in an XHTML document:

<div id="ads">
	<script type="application/javascript" src="smallpox.min.js"></script>
	<script type="application/javascript">
		google_ad_client = "ca-pub-XXXXXXXXXXXXXXXX";
		google_ad_slot = "XXXXXXXXXX";
		google_ad_width = 160;
		google_ad_height = 600;

		smallpox('ads', 'http://pagead2.googlesyndication.com/pagead/show_ads.js');
	</script>
</div>

In this naïve example, loading the Smallpox script blocks the parser, but in a real‐world scenario it should be embedded directly or loaded asynchronously.

smallpox's People

Contributors

illdefined avatar

Watchers

Lars Petersen avatar  avatar James Cloos avatar Vika avatar kloenk 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.