HTML: onpaste=“doSomething();” as invalid attribute

后端 未结 2 766
再見小時候
再見小時候 2021-01-19 17:15

I am checking my HTML code with Amaya.

I have an error on this line:



        
相关标签:
2条回答
  • 2021-01-19 17:56

    http://reference.sitepoint.com/html/extended-event-attributes/onpaste

    "Non-standard event defined by Microsoft for use in Internet Explorer. May work in some other browsers but cannot be reliably used. Compatibility for this non-standard attribute not tested."

    0 讨论(0)
  • 2021-01-19 18:04

    The Amaya editor performs a syntax check using a document type definition, and its built-in repertoire includes only doctypes that do not allow the onpaste attribute. That’s why you get the error message.

    There’s probably no way around this message in Amaya. You can use Tools → Change doctype → Remove the doctype or, better, manually change, in Show Source mode, the doctype declaration to <!doctype html>, the HTML5 doctype. But Amaya still keeps checking against the specification it regards as the correct one.

    Amaya is an editor (and a testbed browser), not a checker. Use a validator to check your syntax. Then you can use <!doctype html> to specify HTML5. Beware that HTML5 has some oddities, and contrary to popular misconceptions, it is not a pure extension of HTML 4.01. And apparently because Amaya decides to remove the attribute, you would need to use a different editor.

    Whether onpaste is useful and safe to use is a different question.

    Update (July 2018): Over the years that have passed, onpaste has not become part of official HTML, so a validator issues an error message about it. Yet, support appears to appear e.g. in Chrome. If you need to avoid validation errors (or your editor removes an onpaste attribute), use JavaScript to assign a value to the onpaste property of the element node instead of using an attribute in HTML markup.

    0 讨论(0)
提交回复
热议问题