javascript pseudo-protocol and event handlers

Discussion in 'Javascript' started by yawnmoth, Jun 23, 2006.

  1. yawnmoth

    yawnmoth Guest

    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?
     
    yawnmoth, Jun 23, 2006
    #1
    1. Advertising

  2. yawnmoth

    Randy Webb Guest

    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.

    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
    Temporarily at: http://members.aol.com/_ht_a/hikksnotathome/cljfaq/
    Javascript Best Practices -
     
    Randy Webb, Jun 23, 2006
    #2
    1. Advertising

  3. yawnmoth

    Matt Kruse Guest

    yawnmoth wrote:
    > 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.

    --
    Matt Kruse
    http://www.JavascriptToolbox.com
    http://www.AjaxToolbox.com
     
    Matt Kruse, Jun 23, 2006
    #3
  4. "yawnmoth" <> writes:

    > 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.
    --
    Lasse Reichstein Nielsen -
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
    'Faith without judgement merely degrades the spirit divine.'
     
    Lasse Reichstein Nielsen, Jun 24, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Deryck
    Replies:
    7
    Views:
    104
  2. yawnmoth
    Replies:
    2
    Views:
    188
    yawnmoth
    Dec 24, 2005
  3. Replies:
    3
    Views:
    112
  4. Ray
    Replies:
    5
    Views:
    95
    Mister Joe
    Mar 7, 2007
  5. Safalra
    Replies:
    2
    Views:
    143
    -Lost
    Mar 30, 2007
Loading...

Share This Page