Connecting Tech Pros Worldwide Help | Site Map

A tag: href vs. onClick

usenet@vikas.mailshell.com
Guest
 
Posts: n/a
: Oct 23 '05
See

<ul>
<li><a name="link1" onClick="alert(this.name);return false;"
href="#">Link1</a></li>
<li><a name="link2" href="javascript:alert(this);">Link2</a></li>
<li>Item 3</li>
</ul>

Clicking on the first list item gives me "link1" because "this" refers
to the A node so this.name returns the value of the name attribute of
that node.

But in the second link, "this" seems to refer to the window node!

Why is this? Why does the meaning of "this" change so drastically when
used in a href=javascript: vs. a onClick=

Thanks

VK
Guest
 
Posts: n/a
#51: Oct 28 '05

re: A tag: href vs. onClick


> >>VK said the following on 10/26/2005 5:56 PM:[color=blue][color=green][color=darkred]
> >><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"
> >>"http://www.w3.org/TR/REC-html40/strict.dtd">
> >><html>
> >><head>
> >><script type="text/vbscript">
> >>Dim MyVar
> >>MyVar = MsgBox ("Hello World!", 216, "MsgBox Example")
> >> ' MyVar contains either 1 or 2, depending on which button is clicked.
> >></script>
> >></head>
> >><body>
> >> <P>This is the body of the document</P>
> >><noscript>
> >> <P>You have scripting disabled</P>
> >></noscript>
> >></body>
> >></html>
> >>[/color]
> >
> > I did not get that I guess. On both Opera 8.01 and FireFox 1.0.7 it
> > ignores VBScript and shows "This is the body of the document" line only
> > in the body. What's wrong with that?
> >[/color]
> Randy Webb wrote:
>
> It does not support the script. So, in theory, it should show the
> noscript element but it doesn't.[/color]


But it does support *the* script! Try <body onload="alert('I support
scripting')">

It simply ignores fragment of unknown Content-Type "text/vbscript"
which seems right to me (?)

If VBScript was a part of common Web standards we would expect 3
separate tags from W3C like:
<NOJSSCRIPT>
<NOVBSCRIPT>
<NOANYSCRIPT>
Otherwise single <NOSCRIPT> is sufficient (?)

If anyone puts her nose out of the ASP box to the client-side, it's her
duty to provide a roll-back for standard browser users.

<script type="text/vbscript">
// Code
</script>
<script type="text/javascript">
// Warning message if VBScript
// was not executed
</script>


P.S. Ave we advocation VBScript ? ;-)

VK
Guest
 
Posts: n/a
#52: Oct 28 '05

re: A tag: href vs. onClick



VK wrote:[color=blue]
> P.S. Ave we advocation VBScript ?[/color]

Wow! Lesser beer - more sport! ;-)

P.S. Are we advocating VBScript?

VK
Guest
 
Posts: n/a
#53: Oct 28 '05

re: A tag: href vs. onClick


Formally thinking over the "VBScript is here but JavaScript is not"
issue we should insist on proper META-EQUIV declaration for used
language as suggested by W3C:
<http://www.w3.org/TR/REC-html40/interact/scripts.html#h-18.2.2.1>
(that was not nice of you to force me to go into Triple-W docs :-)

Naturally it still fails if a language cocktail (VBScript/JScript) is
used on the same page. But in case of VBScript-only it would prevent
script error in the sample below *if it was implemented by anyone*. But
neither of browsers I know of (including FireFox) doesn't respect this
content header.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Testcase</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<meta http-equiv="Content-Script-Type" content="text/vbscript">
<style type="text/css">
<!--
body { background-color: #FFFFFF}
-->
</style>

<script>
Function vbsFunction()
Dim Foo
Foo = MsgBox("VBScript Message Box",64,"Test")
End Function
</script>
</head>

<body onload="vbsFunction()">
<p>No content</p>
</body>
</html>

Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
#54: Oct 28 '05

re: A tag: href vs. onClick


VK wrote:
[color=blue]
> Formally thinking over the "VBScript is here but JavaScript is not"
> issue we should insist on proper META-EQUIV declaration for used
> language as suggested by W3C:
> <http://www.w3.org/TR/REC-html40/interact/scripts.html#h-18.2.2.1>
> (that was not nice of you to force me to go into Triple-W docs :-)[/color]

The MS script engine, which is to my knowledge the only one to support
client-side VBScript, ignores the proper default scripting language
declaration via `meta' element. Instead, it selects the scripting
language in event handler attribute values based on the previously
selected scripting language or a label at the beginning of the event
handler attribute value.
[color=blue]
> Naturally it still fails if a language cocktail (VBScript/JScript) is
> used on the same page. But in case of VBScript-only it would prevent
> script error in the sample below *if it was implemented by anyone*. But
> neither of browsers I know of (including FireFox) doesn't respect this
> content header.
>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">[/color]

To not let Quirks/Compatibility Mode be used by UAs with DOCTYPE switch
feature, a proper system identifier (DTD URL) is missing here.
[color=blue]
> [...]
> <style type="text/css">
> <!--[/color]

Trying to comment out the contents of `style' and `script' elements for UAs
is an obsolete practice in HTML and error-prone in XHTML. Both elements
have already been defined in HTML 3.2 (even if only as placeholders), and
even older specified versions of HTML are (marked as) obsolete by RFC.


PointedEars
Closed Thread