Skip to content Skip to sidebar Skip to footer

Paste Event Modify Content And Return It At The Same Place

I have created this jsfiddle for try to explain what Im trying to do http://jsfiddle.net/nonyck/tyyCN/ $('.autoresize').bind('paste', function(e) { e.preventDefault(); var

Solution 1:

You can get the caret position within the textarea using jQuery to determine where the user wants to paste the text: Cursor position in a textarea (character index, not x/y coordinates)

Then insert your data into that position. See updated fiddle: http://jsfiddle.net/tyyCN/1/

if(data.match("http://.*?.(jpg|png|gif)")) {
         var caret = $(this).getCursorPosition();
         var insert = "<image src='" + data + "' >";
         varval = $('.autoresize').val();
       $('.autoresize').val(val.substring(0, caret) + insert + val.substring(caret, (val.length)));
     }

Post a Comment for "Paste Event Modify Content And Return It At The Same Place"