How to get input value in insert event?

On my site, users can paste text (in this case, url) into the input field. I would like to capture the meaning of the text that was inserted using jQuery. I have this to work in FF using the code below, but it does not work in IE (I don't think IE supports the "paste" event).

Does anyone know how to make this work in all modern browsers? I found several other answers to this on SO, but most of them are only FF, and none of them offer a complete solution.

Here is the code that I still have:

$("input.url").live('paste', function(event) {
    var _this = this;
    // Short pause to wait for paste to complete
    setTimeout( function() {
        var text = $(_this).val();
        $(".display").html(text);
    }, 100);
});

JSFiddle: http://jsfiddle.net/TZWsB/1/

+16
source share
5

jQuery live- - IE; :

$(document).ready(function() {
    $(".url").bind('paste', function(event) {
        var _this = this;
        // Short pause to wait for paste to complete
        setTimeout( function() {
            var text = $(_this).val();
            $(".display").html(text);
        }, 100);
    });
});

Fiddle: http://jsfiddle.net/Trg9F/

+22

change, paste. change , paste , ; , , , , , IME ..

change , , . , input... , HTML5, ( : IE < 9). , :

$('.url').bind('input change paste keyup mouseup',function(e){
    ...
});

, , input, , setInterval.

+16
$('input').on('paste', function(e) {
    // common browser -> e.originalEvent.clipboardData
    // uncommon browser -> window.clipboardData
    var clipboardData = e.clipboardData || e.originalEvent.clipboardData || window.clipboardData;
    var pastedData = clipboardData.getData('text');
});
+14

e.originalEvent.clipboardData.getData('text'); ;

$("input").on("paste", function(e) { 
    var pastedData = e.originalEvent.clipboardData.getData('text');
    // ... now do with pastedData whatever you like ...
});

, -, .

+3

, onblur. , c/p , script , . , c/p, .

0

Source: https://habr.com/ru/post/1544371/


All Articles