Carriage returns removed from textarea when copied to clipboard
Hi guys,
I'm using the following script to copy the contents of a texarea to the clipboard. Seems to only work in IE but that's not an issue as this is a tool for work where everyone uses IE anyway. I'm working with IE9.
Code:
function highlightmetasearch01() {
document.copydata01.text2copy01.select(); document.copydata01.text2copy01.focus(); }
function copymetasearch01() {
highlightmetasearch01();
textRange = document.copydata01.text2copy01.createTextRange();
textRange.execCommand("RemoveFormat");
textRange.execCommand("Copy"); }
The above script is then called with the following markup:
Code:
<form name="copydata01">
Title of template
<button onclick="copymetasearch01();return false;">COPY</button>
<br />
<textarea name="text2copy01">Text with carriage
returns that should be
maintained but aren't!</textarea>
</form>
The problem is that when the text is copied, the carriage returns in the textarea are removed. So the above would output as:
Text with carriage returns that should be maintained but aren't!
...This never used to be a problem with older versions of IE.
The textareas I'm using aren't part of a form to be submitted to a server or email, just static text boxes for people to copy text from.
I tried using the attribute wrap="hard" in the textarea tag but that doesn't fix it (seems to control how the text is sent to a server - but my text isn't going to a server).
Tried re-entering the text manually, as it was originally pasted from a Word document - no joy.
I then found this - http://blog.logiclabz.com/javascript...-textarea.aspx
Tried to call it in the body tag - onload="replacecarriagereturn();" - no joy.
I'll keep digging but does anyone know of a way around this?
thank you