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
2 Answers
Reset to default 7IE 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.