javascript - jQuery ie issue with on paste (content with break) - Stack Overflow

I want to paste a content in an input field (I have to use input field) and get the pasted content to o

I want to paste a content in an input field (I have to use input field) and get the pasted content to other input. my content is like the following (copy all lines and paste):

1234
4567
4321

on all browser the following link works fine but IE

/

        $editor.on('paste', function() {
var $self = $(this);            
              setTimeout(function(){ 
                var $content = $self.val();             
                $clipboard.val($content);
            },100);
     });

when using IE and when paste the content, only the first line (1234) will be appear into the second input. but other browsers you get all the content.

Can anyone help me out here Thanks,

I want to paste a content in an input field (I have to use input field) and get the pasted content to other input. my content is like the following (copy all lines and paste):

1234
4567
4321

on all browser the following link works fine but IE

http://jsfiddle/5bNx4/42/

        $editor.on('paste', function() {
var $self = $(this);            
              setTimeout(function(){ 
                var $content = $self.val();             
                $clipboard.val($content);
            },100);
     });

when using IE and when paste the content, only the first line (1234) will be appear into the second input. but other browsers you get all the content.

Can anyone help me out here Thanks,

Share Improve this question edited Jun 19, 2013 at 4:14 ComeRun asked Jun 19, 2013 at 3:42 ComeRunComeRun 9211 gold badge20 silver badges39 bronze badges 3
  • This working fine in IE9. – Praveen Commented Jun 19, 2013 at 3:47
  • I cant get it to work even on IE9 . did u notice the newlines? – ComeRun Commented Jun 19, 2013 at 4:31
  • Sorry, first I misunderstood your prob, check my answer. – Praveen Commented Jun 19, 2013 at 4:37
Add a ment  | 

2 Answers 2

Reset to default 7

IE fails to handle new line and it will on only paste in the first line and disregard the rest. Replacing newlines characters with space does the trick.

clipped = clipped.replace(/(\r\n|\n|\r)/gm, " "); //replace newlines with spaces

To overe add the below code to your script and this will work fine.

if (window.clipboardData) {
    $('#editor').bind('paste', function (e) {
        var clipped = window.clipboardData.getData('Text');
        clipped = clipped.replace(/(\r\n|\n|\r)/gm, " "); //replace newlines with spaces
        $(this).val(clipped);
        return false; //cancel the pasting event
    });
}

Check this JSFiddle in IE browser.

Reference: Allow Pasting Multiple Lines in IE Textbox

EDIT: Removed console.log

Updated JSFiddle

I don't think IE supports newlines in an 'input'. That means you can't even paste multiple lines into an 'input'. You could use a 'textarea' instead or manipulate the paste before it reaches the input and remove new lines.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745041022a4607807.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信