473,387 Members | 1,517 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,387 software developers and data experts.

Problem with Javascript in <A>

Dear all, according to the ASV3 manual known problem section, to make an <a>
execute some Javascript onclick:

http://www.google.co.uk/search?q=cac...=en&ie=UTF-8#5

4. Due to design limitations of Netscape, avoid using HTML with the
following form: <a href="#" onclick="myScriptWhichModifiesSVG()">The problem
is that JavaScript responds to the onclick event and begins executing the
script, but then Netscape also responds to the fact that you clicked on a
link, and interrupts JavaScript to re-load the current page. This conflict
can be avoided by re-writing the code as follows: <a
href="javascript:myScriptWhichModifiesSVG()">

Now that supposedly only occurs in Netscape, but I'm using IE6 + ASV6 and I
am experiencing the exact same problem:

<a xmlns="http://www.w3.org/2000/svg" xlink:href="#"
onclick="document.getElementById('svg0').setAttrib ute('viewBox','56.8436
42.5733 308.911 143.705'); ">
<path d="bla" etc />
</a>

But if I did:

<a xmlns="http://www.w3.org/2000/svg"
xlink:href="javascript:document.getElementById('sv g0').setAttribute('viewBox
','56.8436 42.5733 308.911 143.705'); ">
<path d="bla" etc />
</a>

This will cause IE to throw an error saying document.getElementById()
returns null, but if I replaced <A> with <G> like below:

<g xmlns="http://www.w3.org/2000/svg"
onclick="javascript:document.getElementById('svg0' ).setAttribute('viewBox','
56.8436 42.5733 308.911 143.705'); ">
<path d="bla" etc />
</g>

It works perfectly fine, and so I have no idea if it is at all possible to
run Javascript in href in SVG anchors. Please help.

Thanks, Julius
Jul 23 '05 #1
1 1983
DU
Julius Mong wrote:
Dear all, according to the ASV3 manual known problem section, to make an <a>
execute some Javascript onclick:

http://www.google.co.uk/search?q=cac...=en&ie=UTF-8#5

4. Due to design limitations of Netscape, avoid using HTML with the
following form: <a href="#" onclick="myScriptWhichModifiesSVG()">
You should use a real, genuine button to make such js call. I would not
use a phony-balloney anchor to modify SVG.

The problem is that JavaScript responds to the onclick event and begins executing the
script, but then Netscape also responds to the fact that you clicked on a
link, and interrupts JavaScript to re-load the current page.
MSIE 6 (or Opera 7.x or any other browser) would do the same too because
you do not cancel the default action of the HTML element, which is to
load in the same page the href attribute value. href="#" usually brings
the page back to the top.

This conflict can be avoided by re-writing the code as follows: <a
href="javascript:myScriptWhichModifiesSVG()">

Use a real button for such call and code the onclick.
Now that supposedly only occurs in Netscape, but I'm using IE6 + ASV6 and I
am experiencing the exact same problem:

<a xmlns="http://www.w3.org/2000/svg" xlink:href="#"
onclick="document.getElementById('svg0').setAttrib ute('viewBox','56.8436
42.5733 308.911 143.705'); ">
<path d="bla" etc />
</a>

An anchor should load another page, a resource somehow. Here, you should
be using an input button or an HTML button instead.
But if I did:

<a xmlns="http://www.w3.org/2000/svg"
xlink:href="javascript:document.getElementById('sv g0').setAttribute('viewBox
','56.8436 42.5733 308.911 143.705'); ">
<path d="bla" etc />
</a>

This will cause IE to throw an error saying document.getElementById()
returns null, but if I replaced <A> with <G> like below:

<g xmlns="http://www.w3.org/2000/svg"
onclick="javascript:document.getElementById('svg0' ).setAttribute('viewBox','
56.8436 42.5733 308.911 143.705'); ">
<path d="bla" etc />
</g>

It works perfectly fine, and so I have no idea if it is at all possible to
run Javascript in href in SVG anchors. Please help.

Thanks, Julius


http://jibbering.com/faq/#FAQ4_24

Top Ten Web-Design Mistakes of 2002
6. JavaScript in Links
"(...) Links that don't behave as expected undermine users'
understanding of their own system. A link should be a simple hypertext
reference that replaces the current page with new content. Users hate
unwarranted pop-up windows. When they want the destination to appear in
a new page, they can use their browser's "open in new window" command --
assuming, of course, that the link is not a piece of code that
interferes with the browser’s standard behavior.
"
http://www.useit.com/alertbox/20021223.html

This is particularly true for href="javascript:window.open(...);" links:
even browsers (like NS 7.x, Mozilla) get confused and get fooled when
examining the properties of such links. Browsers will indicate that the
link will open the referenced resource in the same window while this is
not true!

"
* Don't use javascript: URLs
Using a straight http: URL will allow any browser to access the
link. If you want to use JavaScript for browsers that have JavaScript
enabled, use the onMouseOver and onClick attributes of the <a href> tag.
(...)

Here's a simple example that demonstrates how one can still use
JavaScript while making the site accessible to people with JavaScript
turned off:

* wrong:
<a href="javascript:window.open(blah)">
* right:
<a href="foo.html" target="_blank" onClick="window.open(blah);
return false">
"
http://www.panix.com/~aahz/javascript.html#remove

DU
Jul 23 '05 #2

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

Similar topics

2
by: Eshrath | last post by:
Hi, What I am trying to do: ======================= I need to form a table in html using the xsl but the table that is formed is quite long and cannot be viewed in our application. So we are...
2
by: Donald Firesmith | last post by:
I am having trouble having Google Adsense code stored in XSL converted properly into HTML. The <> unfortunately become &lt; and &gt; and then no longer work. XSL code is: <script...
4
by: Guillaume CABANAC | last post by:
Hi everybody, Does anybody know how to access a remote database (say Oracle) from JavaScript code (within a Firefox Extension) ? I know ADO via ActiveX in the IE world and think a similar...
2
by: Aahz | last post by:
I know this problem has been discussed before but still cannot work it out, here is my code: <span class="popup" onClick = javascript:window.open('fullimage.aspx?id=<%#...
3
by: ajay2552 | last post by:
Hi, I have a query. All html tags start with < and end with >. Suppose i want to display either '<' or '>' or say some text like '<Company>' in html how do i do it? One method is to use &lt,...
14
by: Michael | last post by:
Since the include function is called from within a PHP script, why does the included file have to identify itself as a PHP again by enclosing its code in <?php... <?> One would assume that the...
1
by: Pesho318i | last post by:
Hi all, My question may be too fundamental, but I couldn't find a solution so far. I have a Java servlet deployed in tomcat. Apart from that, I have JavaScript functions which should...
3
by: newbie | last post by:
Same thing g++ complains when using hash_map<>, but is happy with map<--I understand hahs_map is not standardized, but since the compiler didn't complain something like 'hash_map<not defined', I...
9
by: ajos | last post by:
hi all, im getting some problems in my javascript validations..... my jsp code--> 8: <head> 9: <title>Budget Master Administration</title> 10: <meta name="GENERATOR" content="Microsoft...
2
by: optimistx | last post by:
I try to develope a bookmarklet in javascript. The charset of the bookmarklet is UTF-8, but it is supposed to work within pages, whose character set is not UTF-8, but e.g. ISO-8859-1 or...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.