Any idea why this piece of js code in svg doesn't link to target?

R

Raoul.Kamadjeu

I want to dynamically create link to a text on an svg document. I've
implemented this piece of code. Any idea why this doen't link to
google.com?
<svg>
<script onload="init(evt)">
function init(evt) {
var SVGDoc = evt.getTarget().getOwnerDocument();
var text_elem = SVGDoc.getElementById("text_elem");
var a_elem = SVGDoc.createElement("a");
var text_node = SVGDoc.createTextNode("This is a link");
a_elem.setAttributeNS
("http://www.w3.org/2000/xlink","xlink:href","http://www.google.com");
a_elem.setAttribute("id", "link");
a_elem.setAttribute("target", "_blank");
a_elem.appendChild(text_node);
text_elem.appendChild(a_elem);
}
</script>
<text id="text_elem" x="0" y="1em"> </text>
</svg>

Thanks
 
K

Kam-Hung Soh

I want to dynamically create link to a text on an svg document. I've
implemented this piece of code. Any idea why this doen't link to
google.com?
<svg>
<script onload="init(evt)">
function init(evt) {
var SVGDoc = evt.getTarget().getOwnerDocument();
var text_elem = SVGDoc.getElementById("text_elem");
var a_elem = SVGDoc.createElement("a");
var text_node = SVGDoc.createTextNode("This is a link");
a_elem.setAttributeNS
("http://www.w3.org/2000/xlink","xlink:href","http://www.google.com");
a_elem.setAttribute("id", "link");
a_elem.setAttribute("target", "_blank");
a_elem.appendChild(text_node);
text_elem.appendChild(a_elem);
}
</script>
<text id="text_elem" x="0" y="1em"> </text>
</svg>

Thanks

Try:

1. http://www.w3.org/1999/xlink.
2. Replace "xlink:href" with just "href". When using setAttributeNS(),
the first argument is the namespace.

Works on ASV3, but I don't know if it'd work on other browsers.

Regards,
 
R

Raoul.Kamadjeu

No man, you solved my problem, I forgot to replace 2000 by 1999. Thanks
so much.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top