MODELLING AND SIMULATION, WEB ENGINEERING, USER INTERFACES

Code Snippets

DOM

Clone a document (svgDoc) into a new document (svgDoc2).

var impl = document.implementation;
var svgDoc2 = impl.createDocument(svgNs, "svg", null);
svgDoc2.replaceChild(svgDoc.documentElement.cloneNode(true), svgDoc2.documentElement);

Parse an SVG document and add the contents to an HTML body element.

    function parseSVGDocumentFromStringAndAppendToHTMLBody(svgText){
        var parser = new DOMParser()
        var newSVGDoc = parser.parseFromString(svgText)
        var importedSVGRootElement = document.importNode(newSVGDoc.documentElement,true);
        document.body.appendChild(importedSVGRootElement);
    }

JavaScript

Convert non-js Array (arguments array, or Java-native Array in Rhino) to js-native Array

var nativeArray = Array.prototype.slice.call(arguments);
This work is licensed under GPL - 2009 | Powered by Wordpress using the theme aav1