469,314 Members | 2,222 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,314 developers. It's quick & easy.

Element attribute syntax question

I have look in the FAQ, Flanagan's "The definitive guide", and others,
and I am not sure that the following syntax is valid (it is accepted by
both IE and Firefox)
<code>
....
onload="javascript:someFunctionCall();"
....
</code>

I am objecting to the use of 'javascript:'.

Thanks
--
intrader
Mar 22 '08 #1
3 1275
intrader <in******@aol.comwrites:
I have look in the FAQ, Flanagan's "The definitive guide", and others,
and I am not sure that the following syntax is valid (it is accepted
by both IE and Firefox)
<code>
...
onload="javascript:someFunctionCall();"
...
</code>

I am objecting to the use of 'javascript:'.
It's ugly and unnecessary, yes. It *is* valid javascript, though, since
it's interpreted as a labeled statement (the label being "javascript").

Usually you don't want to use strings as event handlers anyway. IOW:
use

onload=someFunctionCall;

instead.

--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
Mar 22 '08 #2
VK
On Mar 22, 10:03 pm, intrader <intra...@aol.comwrote:
I have look in the FAQ, Flanagan's "The definitive guide", and others,
and I am not sure that the following syntax is valid (it is accepted by
both IE and Firefox)
<code>
...
onload="javascript:someFunctionCall();"
...
</code>

I am objecting to the use of 'javascript:'.
Yes, it is valid Javascript syntax for a labeled statement:
http://developer.mozilla.org/en/docs...atements:label

It doesn't have any programmatical sense outside of loop blocks, so
respectively it is valid but pointless for the Javascript itself in
onload="javascript:someFunctionCall();"

The reason one sees it sometimes is that Microsoft has added extra
feature to the label: in intrinsic event handlers it informs the
engine that the following code is JScript and not VBScript.
Respectively it has practical sense only if one has a page viewed in
Internet Explorer, the default scripting language on the page is set
to VBScript, yet some intrinsic event handlers has to be written in
JScript. Unless you need to deal with such ugliness, you don't need
"javascript:" prefix.

Mar 22 '08 #3
VK wrote:
On Mar 22, 10:03 pm, intrader <intra...@aol.comwrote:
>I have look in the FAQ, Flanagan's "The definitive guide", and others,
and I am not sure that the following syntax is valid (it is accepted by
both IE and Firefox)
<code>
...
onload="javascript:someFunctionCall();"
...
</code>

I am objecting to the use of 'javascript:'.

Yes, it is valid Javascript syntax for a labeled statement:
http://developer.mozilla.org/en/docs...atements:label

It doesn't have any programmatical sense outside of loop blocks, so
respectively it is valid but pointless for the Javascript itself in
onload="javascript:someFunctionCall();"

The reason one sees it sometimes is that Microsoft has added extra
feature to the label: in intrinsic event handlers it informs the
engine that the following code is JScript and not VBScript.
Respectively it has practical sense only if one has a page viewed in
Internet Explorer, the default scripting language on the page is set
to VBScript, yet some intrinsic event handlers has to be written in
JScript. Unless you need to deal with such ugliness, you don't need
"javascript:" prefix.
Thank you, I understand the meaning of the syntax and I did not think of
labels as they are so rarely used.
Would two attributes with the same label be considered duplicate, or are
they in a different scope?

--
intrader
Mar 22 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

18 posts views Thread by Tjerk Wolterink | last post: by
8 posts views Thread by Neil Zanella | last post: by
2 posts views Thread by RobG | last post: by
reply views Thread by magister | last post: by
9 posts views Thread by Philipp | last post: by
2 posts views Thread by mjansen.merge.emed | last post: by
2 posts views Thread by anitawa | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.