src/viewer.js
function( ) {
        if ( !THIS[ this.hash ] ) {
            //this viewer has already been destroyed: returning immediately
            return;
        }

        this.close();

        this.clearOverlays();
        this.overlaysContainer.innerHTML = "";

        //TODO: implement this...
        //this.unbindSequenceControls()
        //this.unbindStandardControls()

        if (this.referenceStrip) {
            this.referenceStrip.destroy();
            this.referenceStrip = null;
        }

        if ( this._updateRequestId !== null ) {
            $.cancelAnimationFrame( this._updateRequestId );
            this._updateRequestId = null;
        }

        if ( this.drawer ) {
            this.drawer.destroy();
        }

        this.removeAllHandlers();

        // Go through top element (passed to us) and remove all children
        // Use removeChild to make sure it handles SVG or any non-html
        // also it performs better - http://jsperf.com/innerhtml-vs-removechild/15
        if (this.element){
            while (this.element.firstChild) {
                this.element.removeChild(this.element.firstChild);
            }
        }

        // destroy the mouse trackers
        if (this.innerTracker){
            this.innerTracker.destroy();
        }
        if (this.outerTracker){
            this.outerTracker.destroy();
        }

        THIS[ this.hash ] = null;
        delete THIS[ this.hash ];

        // clear all our references to dom objects
        this.canvas = null;
        this.container = null;

        // clear our reference to the main element - they will need to pass it in again, creating a new viewer
        this.element = null;
    }
function( ) {
        if ( !THIS[ this.hash ] ) {
            //this viewer has already been destroyed: returning immediately
            return;
        }

        this.close();

        this.clearOverlays();
        this.overlaysContainer.innerHTML = "";

        //TODO: implement this...
        //this.unbindSequenceControls()
        //this.unbindStandardControls()

        if (this.referenceStrip) {
            this.referenceStrip.destroy();
            this.referenceStrip = null;
        }

        if ( this._updateRequestId !== null ) {
            $.cancelAnimationFrame( this._updateRequestId );
            this._updateRequestId = null;
        }

        if ( this.drawer ) {
            this.drawer.destroy();
        }

        this.removeAllHandlers();

        // Go through top element (passed to us) and remove all children
        // Use removeChild to make sure it handles SVG or any non-html
        // also it performs better - http://jsperf.com/innerhtml-vs-removechild/15
        if (this.element){
            while (this.element.firstChild) {
                this.element.removeChild(this.element.firstChild);
            }
        }

        // destroy the mouse trackers
        if (this.innerTracker){
            this.innerTracker.destroy();
        }
        if (this.outerTracker){
            this.outerTracker.destroy();
        }

        THIS[ this.hash ] = null;
        delete THIS[ this.hash ];

        // clear all our references to dom objects
        this.canvas = null;
        this.container = null;

        // clear our reference to the main element - they will need to pass it in again, creating a new viewer
        this.element = null;
    }
function ( ) { if ( ! THIS [ this . hash ] ) { //this viewer has already been destroyed: returning immediately return ; } this . close ( ) ; this . clearOverlays ( ) ; this . overlaysContainer . innerHTML = "" ; //TODO: implement this... //this.unbindSequenceControls() //this.unbindStandardControls() if ( this . referenceStrip ) { this . referenceStrip . destroy ( ) ; this . referenceStrip = null ; } if ( this . _updateRequestId !== null ) { $ . cancelAnimationFrame ( this . _updateRequestId ) ; this . _updateRequestId = null ; } if ( this . drawer ) { this . drawer . destroy ( ) ; } this . removeAllHandlers ( ) ; // Go through top element (passed to us) and remove all children // Use removeChild to make sure it handles SVG or any non-html // also it performs better - http://jsperf.com/innerhtml-vs-removechild/15 if ( this . element ) { while ( this . element . firstChild ) { this . element . removeChild ( this . element . firstChild ) ; } } // destroy the mouse trackers if ( this . innerTracker ) { this . innerTracker . destroy ( ) ; } if ( this . outerTracker ) { this . outerTracker . destroy ( ) ; } THIS [ this . hash ] = null ; delete THIS [ this . hash ] ; // clear all our references to dom objects this . canvas = null ; this . container = null ; // clear our reference to the main element - they will need to pass it in again, creating a new viewer this . element = null ; }
Function to destroy the viewer and clean up everything created by OpenSeadragon.

Example:
var viewer = OpenSeadragon({
[...]
});

//when you are done with the viewer:
viewer.destroy();
viewer = null; //important

@function
Function to destroy the viewer and clean up everything created by OpenSeadragon .