Forum Moderators: open

Message Too Old, No Replies

SVG + Javascript dynamic xlink

         

magna doodle

3:20 pm on Nov 9, 2010 (gmt 0)

10+ Year Member



Hi,
I have a .svg file with a "line" Element with a link to an new page.
This means that if you click on the line a new page will open.

Here is a part of the code from the .svg file:

<svg version="1.1"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
width="530" height="530"
onload="init(evt);"
font-size="12">


<a xlink:href="./relations.and.abstracts/rel-1.html" target="_blank">
<line id="Line1" x1="310" x2="220" y1="310" y2="220" stroke="silver" stroke-width="2"/>
</a>

You see the line element is embedded in a 'a'.

Now I repaint the line in a Javacript file with the DOM:

svgDocument.documentElement.appendChild("lineID");

The line is now on top of the z-index this is what I want but the problem is that the link when you click on the line is disappeared.
Now I tried to get access to the line Object and add a link.

svgDocument.getElementById("lineID").addEventListener("click", getAttributes, false);

This works when i click on the line the function getAttributes() is called.

But when i want to set a link like this nothing happens:

svgDocument.getElementById("lineID").setAttributeNS("http://www.w3.org/1999/xlink/namespace/", "href", "http://www.google.com/");

Has anabody an Idea how to create a link to another page with a DOM Object? I tried all variations of the setAttributeNS() and the setAttribute() Function.

Even I tried to Capsule the line Object in an Anchor Object with a link like in the .svg file.

Does anybody know how to set a link for a DOM Object?

Fotiman

3:58 pm on Nov 9, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Welcome to WebmasterWorld! I don't know if this will work (I'm not really familiar with svg), but have you tried this?

svgDocument.getElementById("lineID").href = "http://www.google.com";

magna doodle

4:02 pm on Nov 9, 2010 (gmt 0)

10+ Year Member



Yes i tried but it does not work ;(

daveVk

1:17 am on Nov 10, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<a xlink:href="./relations.and.abstracts/rel-1.html" target="_blank">
<line id="Line1" x1="310" x2="220" y1="310" y2="220" stroke="silver" stroke-width="2"/>
</a>


is href valid on line elements ?

Maybe you need to change red attribute instead ?