Given this:
<?xml version="1.0" standalone="yes"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="100px" height="100px" version="1.1"
xmlns="http://www.w3.org/2000/svg"
>
<text
x="20"
y="20"
onload="alert('load'); setAttribute('fill', 'fuchsia')"
onclick="setAttribute('fill', 'lightgreen')"
onmouseout="setAttribute('fill', 'black')"
>Load me</text>
</svg>
I would expect to see pink text when the svg was opened. onclick and onmouseout work as expected.
This doesn't happen in firefox. IE can't open it, period.
Any explanations?
Use onload
event on <svg>
element. This works fine on all browsers.
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<svg onload="init(evt)" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:gui="http://www.kevlindev.com/gui">
<script>var info,infoElem;
function init(e) {
if ( window.svgDocument == null )
svgDocument = e.target.ownerDocument;
infoElem = svgDocument.getElementById("info");
infoElem.setAttributeNS(null,"fill", "fuchsia");
}
function changeColor(c){
infoElem.setAttributeNS(null,"fill", c);
}</script>
<text id="info" x="20" y="20" onclick="changeColor('lightgreen')" onmouseout="changeColor('black')">Load me</text>
</svg>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With