Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #11978

Re: onclick=function(){obj.meth()}

From Stefan Weiss <krewecherl@gmail.com>
Newsgroups comp.lang.javascript
Subject Re: onclick=function(){obj.meth()}
Date 2012-02-21 02:13 +0100
Organization albasani.net
Message-ID <jhur4e$2q0$1@news.albasani.net> (permalink)
References <jp45k75qbcjbb5v8tavnmognds11hjihdh@4ax.com> <4f429d06$0$6981$e4fe514c@news2.news.xs4all.nl> <9qflqrFfeeU1@mid.uni-berlin.de> <_56dnWhXdrA-e9_SnZ2dnUVZ8ridnZ2d@giganews.com>

Show all headers | View raw


On 2012-02-21 01:34, Richard Cornford wrote:
> Jake Jarvis wrote:
>> It's not about just compiling/passing as syntactically valid js
>> program on the first level, the real problem manifests itself
>> "later", when actually clicking the resulting anchor.
> 
> As you say, the real problem will manifest itself later, but that later 
> will not be when anchor is clicked.  The issue here is a syntax error; 
> an Expression statement is forbidden from commencing with the - 
> function - keyword by the language's syntax rules, because that would be 
> ambiguous with a function declaration. And the point when that syntax 
> error will manifest itself will be when the javascript string defined in 
> the function above is processed through an HTML parser (probably via the 
> use of innerHTML, but maybe - document.write -). At that point the 
> browser must use the text of the - ONCLICK - attribute in the HTML to 
> create a javascript function object to assign to the DOM element 
> representation's - onclick - property, which is will not be able to do 
> because the HTML attribute value contains a javascript syntax error.

You're right about the cause of the syntax error, of course, but I beg
to differ about the rest. What the HTML parser does when it encounters
invalid JS in an event handler attribute is completely up to the
implementation. All it is required to do (if scripting is available and
enabled) is register the presence of the onclick attribute, and leave
the rest for the JS engine. After all, the contents of that attribute
could change at any time, so why bother pre-parsing it.

  <a href="#" onclick="|-">.</a>
  <!-- in the main document HTML -->

Firefox, Chrome, Opera, Safari don't blink an eye about this, until the
user clicks the link. Imagine my surprise when I found out that IE8
handles it differently, and does throw a syntax error (I didn't have an
IE9 for testing available).


- stefan

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

onclick=function(){obj.meth()} Puzzled <scratching.head@example.com> - 2012-02-20 14:02 -0500
  Re: onclick=function(){obj.meth()} "Tom de Neef" <tdeneef@qolor.nl> - 2012-02-20 20:20 +0100
    Re: onclick=function(){obj.meth()} Jake Jarvis <pig_in_shoes@yahoo.com> - 2012-02-20 20:39 +0100
      Re: onclick=function(){obj.meth()} "Richard Cornford" <Richard@litotes.demon.co.uk> - 2012-02-21 00:34 +0000
        Re: onclick=function(){obj.meth()} Stefan Weiss <krewecherl@gmail.com> - 2012-02-21 02:13 +0100
          Re: onclick=function(){obj.meth()} Richard Cornford <Richard@litotes.demon.co.uk> - 2012-02-21 04:05 -0800
        Re: onclick=function(){obj.meth()} Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-02-21 12:47 +0100
          Re: onclick=function(){obj.meth()} John G Harris <john@nospam.demon.co.uk> - 2012-02-21 15:59 +0000
  Re: onclick=function(){obj.meth()} Stefan Weiss <krewecherl@gmail.com> - 2012-02-20 21:09 +0100
    Re: onclick=function(){obj.meth()} "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-02-20 20:29 +0000
      Re: onclick=function(){obj.meth()} Puzzled <scratching.head@example.com> - 2012-02-20 16:50 -0500
        Re: onclick=function(){obj.meth()} "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-02-21 11:33 +0000
    Re: onclick=function(){obj.meth()} Puzzled <scratching.head@example.com> - 2012-02-20 15:47 -0500
      Re: onclick=function(){obj.meth()} Jake Jarvis <pig_in_shoes@yahoo.com> - 2012-02-20 22:38 +0100
        Re: onclick=function(){obj.meth()} Puzzled <scratching.head@example.com> - 2012-02-20 17:12 -0500
      Re: onclick=function(){obj.meth()} Gene Wirchenko <genew@ocis.net> - 2012-02-20 14:04 -0800
        "The this value" (Was: onclick=function(){obj.meth()}) Stefan Weiss <krewecherl@gmail.com> - 2012-02-21 01:37 +0100
          Re: "The this value" (Was: onclick=function(){obj.meth()}) Gene Wirchenko <genew@ocis.net> - 2012-02-20 17:20 -0800
          Re: "The this value" (Was: onclick=function(){obj.meth()}) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-02-21 13:44 +0100
            Re: "The this value" (Was: onclick=function(){obj.meth()}) Stefan Weiss <krewecherl@gmail.com> - 2012-02-21 22:31 +0100
              Re: "The this value" (Was: onclick=function(){obj.meth()}) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-02-22 10:55 +0100
                Re: "The this value" (Was: onclick=function(){obj.meth()}) John G Harris <john@nospam.demon.co.uk> - 2012-02-22 15:58 +0000
        Re: onclick=function(){obj.meth()} "Richard Cornford" <Richard@litotes.demon.co.uk> - 2012-02-21 01:30 +0000
      Re: onclick=function(){obj.meth()} Scott Sauyet <scott.sauyet@gmail.com> - 2012-02-20 13:43 -0800
      Re: onclick=function(){obj.meth()} Stefan Weiss <krewecherl@gmail.com> - 2012-02-20 23:17 +0100
        Re: onclick=function(){obj.meth()} Puzzled <scratching.head@example.com> - 2012-02-20 17:48 -0500
          Re: onclick=function(){obj.meth()} Stefan Weiss <krewecherl@gmail.com> - 2012-02-21 00:57 +0100
          Re: onclick=function(){obj.meth()} "Richard Cornford" <Richard@litotes.demon.co.uk> - 2012-02-21 01:03 +0000
            Re: onclick=function(){obj.meth()} Gene Wirchenko <genew@ocis.net> - 2012-02-20 19:05 -0800
              Re: onclick=function(){obj.meth()} Richard Cornford <Richard@litotes.demon.co.uk> - 2012-02-21 04:14 -0800
                Re: onclick=function(){obj.meth()} Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-02-21 13:54 +0100
                Re: onclick=function(){obj.meth()} Gene Wirchenko <genew@ocis.net> - 2012-02-21 10:17 -0800
                Re: onclick=function(){obj.meth()} Scott Sauyet <scott.sauyet@gmail.com> - 2012-02-21 11:57 -0800
                Re: onclick=function(){obj.meth()} Gene Wirchenko <genew@ocis.net> - 2012-02-21 13:39 -0800
                Re: onclick=function(){obj.meth()} Scott Sauyet <scott.sauyet@gmail.com> - 2012-02-22 05:07 -0800
            Re: onclick=function(){obj.meth()} Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-02-21 12:58 +0100
        Re: onclick=function(){obj.meth()} "Richard Cornford" <Richard@litotes.demon.co.uk> - 2012-02-21 00:45 +0000
          Re: onclick=function(){obj.meth()} Stefan Weiss <krewecherl@gmail.com> - 2012-02-21 02:22 +0100
        Re: onclick=function(){obj.meth()} Puzzled <scratching.head@example.com> - 2012-02-21 08:12 -0500
          Re: onclick=function(){obj.meth()} Scott Sauyet <scott.sauyet@gmail.com> - 2012-02-21 11:14 -0800

csiph-web