Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-10-2012, 10:36 AM   PM User | #1
Subyne Simean
New Coder

 
Join Date: Nov 2006
Posts: 21
Thanks: 3
Thanked 1 Time in 1 Post
Subyne Simean is an unknown quantity at this point
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.

Tried removing this textRange.execCommand("RemoveFormat"); from the script - no joy.

I'll keep digging but does anyone know of a way around this?

thank you
Subyne Simean is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:27 AM.


Advertisement
Log in to turn off these ads.