It works ONLY in Opera.
I have two problems:
(1) Why only in Opera?
(2) How to dispense with the HTML, keeping only the JS which generates the SVG.
Here's the HTML:
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Test Boxes</title>
<script type="text/javascript" src="svg.js"></script>
</head>
<body onload="init()">
</body>
</html>
Here's the external JS :
Code: Select all
var svgns = "http://www.w3.org/2000/svg";
var svg; <!-- svg <svg> -->
var g1, g2, g3; <!-- Groups <g> -->
var r1, r2, r3; <!-- Rects <rect> -->
var a1, a2, a3; <!-- Buttons -->
var b1, b2, b3;
var c1, c2, c3;
function initSVG()
{
svg = document.createElementNS(svgns, 'svg');
svg.setAttributeNS(svgns, 'width', '250');
svg.setAttributeNS(svgns, 'height', '250');
svg.setAttributeNS(svgns, 'version', '1.1');
document.body.appendChild(svg);
}
function rct(i, x,y, w,h, s,f)
{
var rc;
rc = document.createElementNS(svgns, 'rect');
rc.setAttributeNS(svgns, "id", i);
rc.setAttributeNS(svgns, "x", x);
rc.setAttributeNS(svgns, "y", y);
rc.setAttributeNS(svgns, "width", w);
rc.setAttributeNS(svgns, "height", h);
rc.setAttributeNS(svgns, "stroke", s);
rc.setAttributeNS(svgns, "fill", f);
return rc;
}
function txt(i, x,y, w)
{
var cc = document.createTextNode(w);
var tx = document.createElementNS(svgns, "text");
tx.setAttributeNS(svgns, "id", i);
tx.setAttributeNS(svgns, "x", x);
tx.setAttributeNS(svgns, "y", y);
tx.appendChild(cc);
return tx;
}
function doBox(i, g,r, x,y,w,h, s,f)
{
var tx, xt, yt;
g = document.createElementNS(svgns, "g");
svg.appendChild(g);
g.setAttribute("id", i);
r = rct(i,x,y,w,h,s,f);
g.appendChild(r);
xt=parseInt(x)+6; yt=parseInt(y)+16;
tx = txt(null, xt+'', yt+'', i);
g.appendChild(tx);
}
function init()
{
initSVG();
g1=doBox("wrap",g1,r1,"10","10","230","230","#000","#999");
g2=doBox("main",g2,r2,"30","40","190","180","#000","#bbb");
g3=doBox("cont",g3,r3,"50","70","150","130","#000","#ddd");
a1=doBox("A1",a1,null,"70","100","30","20","#000","#fff");
b1=doBox("B1",b1,null,"110","100","30","20","#000","#fff");
c1=doBox("C1",c1,null,"150","100","30","20","#000","#fff");
a2=doBox("A2",a2,null,"70","130","30","20","#000","#fff");
b2=doBox("B2",b2,null,"110","130","30","20","#000","#fff");
c2=doBox("C2",c2,null,"150","130","30","20","#000","#fff");
a3=doBox("A3",a3,null,"70","160","30","20","#000","#fff");
b3=doBox("B3",b3,null,"110","160","30","20","#000","#fff");
c3=doBox("C3",c3,null,"150","160","30","20","#000","#fff");
}
Hoping for answers,
Thanks,
JJ