Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IE input event for contenteditable?

I am wondering if there is a polyfill to support the contenteditable input event in IE11?

I am specifically talking about this event: http://jsfiddle.net/ch6yn/

Which fires whenever a change happens on a contenteditable div regardless of the source (e.g. copy/paste/drag/drop/type etc).

<div contenteditable="true" id="editor">Please type something in here</div>
<script>
document.getElementById("editor").addEventListener("input", function() {
    alert("input event fired");
}, false);
</script>
like image 901
Hailwood Avatar asked Feb 25 '14 04:02

Hailwood


1 Answers

Ran into this today, this was how I solved it..

Solution: Change event name --> "textinput" works in IE 11 for event attachment - just be sure you let the other browsers use "input".

Example:

    //Check for IE ('Trident')
    var eventType = /Trident/.test( navigator.userAgent ) ? 'textinput' : 'input';

    //Attach your event
    this.refs.captionInput.addEventListener( eventType, this.handleChangeCaption );
like image 60
Lux.Capacitor Avatar answered Nov 06 '22 12:11

Lux.Capacitor