Closed Bug 642753 Opened 14 years ago Closed 14 years ago

Allow `oninput` feature detection

Categories

(Core :: DOM: Core & HTML, defect)

x86
macOS
defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 414853

People

(Reporter: mathias, Unassigned)

References

()

Details

(Keywords: html5)

User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_6) AppleWebKit/534.25 (KHTML, like Gecko) Chrome/12.0.706.0 Safari/534.25 Build Identifier: Firefox has supported the `oninput` event at least since version 2. However, for some reason the following evaluates as `false`: 'oninput' in document.createElement('input'); // false I would expect 'oninput' in document.createElement('input') to return true, since the oninput event and the attribute are supported. There is still a way to feature test for oninput support in Firefox, but it involves using the event API to create an input and fake a keypress to see if oninput fires, which is more complicated than it should be. (See http://blog.danielfriesen.name/2010/02/16/html5-browser-maze-oninput-support/ for more details.) Reproducible: Always Steps to Reproduce: 1. Open data:text/html,<script>alert('oninput' in document.createElement('input')?'PASS':'FAIL')</script> Actual Results: FAIL Expected Results: Firefox should alert “PASS” because it supports `oninput`. Seems like Firefox is being modest.
Version: unspecified → Trunk
This is bug 414853. Maybe we want to special case?
Component: General → DOM: Core & HTML
Depends on: 414853
Keywords: html5
Product: Firefox → Core
QA Contact: general → general
I don't understand why you need a fake keypress. javascript:document.documentElement.oninput = function() {alert("input");}; var e = document.createEvent("Event");e.initEvent("input", false, false); document.documentElement.dispatchEvent(e); void(0)
Isn't that bug a dup of bug 414853?
Status: UNCONFIRMED → RESOLVED
Closed: 14 years ago
Resolution: --- → DUPLICATE
(In reply to comment #2) > I don't understand why you need a fake keypress. > > javascript:document.documentElement.oninput = function() {alert("input");}; var > e = document.createEvent("Event");e.initEvent("input", false, false); > document.documentElement.dispatchEvent(e); void(0) I cannot make that test work (FF3.6.15 Mac). Should DOM2 dispatchEvent fire DOM0 events ? Are "input" events valid for any element or just focusable elements ?
element.oninput was added for FF4, Bug 618948 If you want to test oninput as attribute you could do javascript: var el = document.createElement("div"); el.setAttribute("oninput", "alert('input')"); var e = document.createEvent("Events"); e.initEvent("input", false, false); el.dispatchEvent(e); void(0); And yes, oninput should work in all HTMLElements. http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#handler-oninput
(In reply to comment #6) > element.oninput was added for FF4, Bug 618948 > > If you want to test oninput as attribute you could do > javascript: var el = document.createElement("div"); el.setAttribute("oninput", > "alert('input')"); var e = document.createEvent("Events"); e.initEvent("input", > false, false); el.dispatchEvent(e); void(0); > > And yes, oninput should work in all HTMLElements. > http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#handler-oninput Thank you for the tips and the updates. Still looking at this description: http://dev.w3.org/html5/spec/Overview.html#event-input-input "When the input event applies, any time the user causes the element's [value] to change, ..." I don't see how "element's value" can change for elements which are not form controls. Is it just a discrepancy or did I get that wrong ?
input event bubbles, so any parent node of <input> or <textarea> element may get it.
You need to log in before you can comment on or make changes to this bug.