473,378 Members | 1,482 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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

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 '06 #1
5 1523
Ra************@gmail.com 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

Jun 13 '06 #2

Kam-Hung Soh wrote:
Ra************@gmail.com 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 '06 #3

Kam-Hung Soh wrote:
Ra************@gmail.com 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 '06 #4
Ra************@gmail.com 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 14 '06 #5
No man, you solved my problem, I forgot to replace 2000 by 1999. Thanks
so much.

Kam-Hung Soh wrote:
Ra************@gmail.com 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 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

242
by: James Cameron | last post by:
Hi I'm developing a program and the client is worried about future reuse of the code. Say 5, 10, 15 years down the road. This will be a major factor in selecting the development language. Any...
16
by: Luca | last post by:
About one month ago I have inserted in my web site a clickcounter who controls the access to almost every link, but this script who changed the path in every link so the search engines couldn't...
7
by: terry | last post by:
Hi, I think i made a mistake somewhere.... I can execute the following line of code with Firefox but not IE... someone pls help! <a href="#" onclick="window.open('video.html', 'Concert 2003:...
36
by: randau | last post by:
I would like to use the Link Target attribute, but am inhibited by the likelihood of a newly opened browser window completely hiding the Parent browser window. Thus offering the illusion that...
21
by: petermichaux | last post by:
Hi, I've been asking questions about library design over the last week and would like to get feedback on my overall idea for a JavaScript GUI library. I need a nice GUI library so there is a...
6
by: kalyan.listsubs | last post by:
Hi, I have the below program which will simply write struct employee to a file (binary mode). The problem here is empid is writen to the file but the name (char name) is not written. I am using...
17
by: Mark | last post by:
I must create a routine that finds tokens in small, arbitrary VB code snippets. For example, it might have to find all occurrences of {Formula} I was thinking that using regular expressions...
6
by: robertsherman | last post by:
I'm new at js, so go easy on me. I need some js code to run AFTER returning to a page from an external page. If I use onfocus, and I link away using target=_blank to spawn a new window, it works...
3
by: lzo53 | last post by:
this is the code to a photogallery that displays thumbnails when clicked on a window opens my problem is i wish to customize the size of the window height 500 width 400 scrollbars no resize no and so...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.