Hi i'm using below code to build a string and copying it,but in output when i paste it the line break is not applying
function copyToClipboardShipto() {
var $temp = $("<input>");
$("body").append($temp);
var str1 = "@(Model.firstName)"; var str2 = " "; var str3 = "@(Model.lastName)"; var str4 = "\n";
var str5 = "@(Model.shiptoes[0].address.address1)";
var str6 = ",";
var str7 = "@(Model.shiptoes[0].address.address2)";
var str8 = "\n";
var str9 = "@(Model.shiptoes[0].address.city)"; var str10 = ","; var str11 = "@(Model.shiptoes[0].address.state)"; var str12 = "\n";
var str13 = "@(Model.shiptoes[0].address.zip)";
var str = str1 + str2 + str3 + str4 + str5 + str6 + str7 + str8 + str9 + str10 + str11 + str12 + str13;
$temp.val(str).select();
document.execCommand("copy");
$temp.remove();
}
}
firstname lastname223 E JACKSON AVE,city,statezip any help appericiated
When an HTML document has been switched to designMode , its document object exposes an execCommand method to run commands that manipulate the current editable region, such as form inputs or contentEditable elements.
The newline character is \n in JavaScript and many other languages. All you need to do is add \n character whenever you require a line break to add a new line to a string.
“vs code copy line to next line” Code Answer On Windows: Shift + Alt + Up/Down. On Mac: Shift + Option + Up/Down. On Ubuntu: Ctrl + Shift + Alt + Up/Down.
Use <textarea>
instead of <input>
, since INPUT doesn't support multiline strings.
var $temp = $("<textarea>");
Use <textarea>
instead as <input>
wont support line breaks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With