access svg function from html

i found some examples on the internet about what i need, but when it comes to my code it just doesn't work. here is the code
html file:

<html>
<body>
<embed src = "a.svg" width = "300px" height = "300px" id = "svg"/>
<input type = "submit" value = "click" onlick = "createRectangle()"/>
</body>
</html>

svg file:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="300" height="300">
<script type="text/ecmascript"><![CDATA[
var svgNS = "http://www.w3.org/2000/svg";
var xlinkNS = "http://www.w3.org/1999/xlink";

parent.createRectangle = createRect;

function createRect(){
var newRect = document.createElementNS(svgNS,"rect");
newRect.setAttributeNS(null,"width",Math.random() * 100);
newRect.setAttributeNS(null,"height",Math.random() * 100);
newRect.setAttributeNS(null,"x",Math.random() * 250);
newRect.setAttributeNS(null,"y",Math.random() * 180 + 60);
newRect.setAttributeNS(null,"fill-opacity",Math.random());
var red = Math.round(Math.random() * 255);
var green = Math.round(Math.random() * 255);
var blue = Math.round(Math.random() * 255);
newRect.setAttributeNS(null,"fill","rgb("+ red +","+ green+","+blue+")");
document.getElementById("firstGroup").appendChild(newRect);
}

]]></script>
<g id="firstGroup">

</g>
</svg>

it works if i put a button in the svg that calls createRect so that function is good

Comments

Test

viagra , cialis , viagra ,

viagra , cialis , viagra ,

cialis , viagra , viagra ,

cheap viagra , buy cialis ,

buy viagra , cheap cialis ,

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Post new comment

  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.