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

Discussion in 'Javascript' started by Raoul.Kamadjeu@gmail.com, Jun 13, 2006.

  1. Guest

    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
     
    , Jun 13, 2006
    #1
    1. Advertising

  2. Kam-Hung Soh Guest

    wrote:
    > 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,

    --
    Kam-Hung Soh
    http://kamhungsoh.blogspot.com - It Mostly Works
    http://members.optusnet.com.au/khsoh - Software That Mostly Works
     
    Kam-Hung Soh, Jun 13, 2006
    #2
    1. Advertising

  3. Guest

    Kam-Hung Soh wrote:
    > wrote:
    > > 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,
    >
    > --
    > Kam-Hung Soh
    > http://kamhungsoh.blogspot.com - It Mostly Works
    > http://members.optusnet.com.au/khsoh - Software That Mostly Works


    Nope, it doesn't
     
    , Jun 14, 2006
    #3
  4. Guest

    Kam-Hung Soh wrote:
    > wrote:
    > > 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,
    >
    > --
    > Kam-Hung Soh
    > http://kamhungsoh.blogspot.com - It Mostly Works
    > http://members.optusnet.com.au/khsoh - Software That Mostly Works


    By the way, cool.. the game
     
    , Jun 14, 2006
    #4
  5. Kam-Hung Soh Guest

    Kam-Hung Soh, Jun 14, 2006
    #5
  6. Guest

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

    Kam-Hung Soh wrote:
    > wrote:
    >
    > > By the way, cool.. the game

    >
    > Thanks. Sorry I couldn't solve your problem.
    >
    > --
    > Kam-Hung Soh
    > http://kamhungsoh.blogspot.com - It Mostly Works
    > http://members.optusnet.com.au/khsoh - Software That Mostly Works
     
    , Jun 15, 2006
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Arne Nordmann
    Replies:
    0
    Views:
    533
    Arne Nordmann
    Jun 28, 2004
  2. Moritz Beller
    Replies:
    19
    Views:
    689
    Pete Becker
    Jun 4, 2004
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,994
    Smokey Grindel
    Dec 2, 2006
  4. Patrick Plattes

    Download a file piece by piece

    Patrick Plattes, Nov 30, 2006, in forum: Ruby
    Replies:
    2
    Views:
    207
    Patrick Plattes
    Nov 30, 2006
  5. Jack Wang
    Replies:
    5
    Views:
    96
    Mario D'Alessio
    Feb 15, 2008
Loading...

Share This Page