javascript pseudo-protocol and event handlers

Y

yawnmoth

I've seen a few webpages that use the javascript pseudo-protocol with
event handlers. eg.

<input onkeyup="javascript: ..." />

Correct me if I'm wrong, but isn't onkeyup always supposed to be
javascript, anyway? As such, isn't usint hte javascript
pseudo-protocol redundant?

....or was it required on some archaic browser like Netscape 4.0 or
something?
 
R

Randy Webb

yawnmoth said the following on 6/23/2006 4:41 PM:
I've seen a few webpages that use the javascript pseudo-protocol with
event handlers. eg.

<input onkeyup="javascript: ..." />

Usually because they don't know better. Or, they are using VBScript in
the same page.
Correct me if I'm wrong, but isn't onkeyup always supposed to be
javascript, anyway? As such, isn't usint hte javascript
pseudo-protocol redundant?

Depending on whether it is IE or not and what the default script
language in the page is.
....or was it required on some archaic browser like Netscape 4.0 or
something?

No.
 
M

Matt Kruse

yawnmoth said:
Correct me if I'm wrong, but isn't onkeyup always supposed to be
javascript, anyway? As such, isn't usint hte javascript
pseudo-protocol redundant?

Kind of redundant, but in reality it's a completely different meaning that
uses the same syntax by chance.

In an example like
<input onkeyup="javascript: ..." />

the "javascript:" is acting as a label, which is allow in javascript code.
So it doesn't create an error, even thouh it serves no purpose and is surely
caused by someone not understand what the javascript: pseudo-protocol is and
where it (used to) be used.
 
L

Lasse Reichstein Nielsen

yawnmoth said:
I've seen a few webpages that use the javascript pseudo-protocol with
event handlers. eg.

<input onkeyup="javascript: ..." />

Correct me if I'm wrong, but isn't onkeyup always supposed to be
javascript, anyway?

It's supposed to be the script langauge set as the Content-Script-Type
(e.g., <meta http-equiv="Content-Script-Type" content="text/javascript">)
but all browsers default to Javascript if nothing else is specified.

In IE, it's possible to have a default language of VBScript. In order
to allow event handlers in Javascript anyway, the prefix "javascript:"
will make IE treat the content as Javascript independently of what
the default language is.

In all other browsers it's just a label, which can be seen by this
example:
<div onclick="javascript:while(true){break javascript;}alert('done')">
X</div>
click the X and see an alert in non-IE browsers and an error in IE
(unknown label).
As such, isn't usint hte javascript pseudo-protocol redundant?

If that was what it meant, it would be redundant. Actually, it's just
misguided.
...or was it required on some archaic browser like Netscape 4.0 or
something?

No, never. The only place where it has any use is in multi-script-
language pages written specifically for IE. In a page meant for the
internet, any occurence of "javascript:" should be considered a
problem[1]

/L
[1] Unless you are showing off your bookmarklets.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top