--- In svg-developers@yahoogroups.com, "Kam-Hung Soh"
<kamhung.soh@...> wrote:
> I'm would like to programmatically create SVG elements using
> Javascript in MSIE + ASV.
>
> I have an SVG element embedded in an XHTML document like this:
> <svg:svg>...</svg:svg>
>
> The XHTML document is tricked up to support MSIE + ASV like this:
>
> <object id="AdobeSVG"
> classid="clsid:78156a80-c6a1-4bbf-8e6a-3cd390eeb4e2"> </object>
> <?import namespace="svg" urn="http://www.w3.org/2000/svg"
> implementation="#AdobeSVG"?>
One possible way (not sure there are others) is to get the svg element
in the HTML DOM that IE implements, then access the SVG DOM document
the Adobe plugin implements and then simply use the W3C DOM Level 2
createElementNS the SVG DOM document implemented by Adobe provides,
e.g. if you have
<div>
<svg:svg width="200px" height="200px"
id="svg1">
<svg:circle cx="100" cy="100" r="30" fill="green" />
</svg:svg>
</div>
then you can do
var svgElement = document.getElementById('svg1');
if (svgElement != null && typeof svgElement.getSVGDocument !=
'undefined') {
var svgDocument = svgElement.getSVGDocument();
var rect =
svgDocument.createElementNS('http://www.w3.org/2000/svg', 'rect');
rect.setAttributeNS(null, 'x', '30');
rect.setAttributeNS(null, 'y', '30');
rect.setAttributeNS(null, 'width', '20');
rect.setAttributeNS(null, 'height', '20');
rect.setAttributeNS(null, 'fill', 'blue');
svgDocument.documentElement.appendChild(rect);
}