JavaScript Javascript : how to preserve newlines with textContent in Firefox? js-beautify preserve newlines

I have a div contenteditable in my web page. When you type some text inside the div contenteditable, the text is reproduced in a hidden textarea for the post treatment (form method="post" action="...").

For that, I retrieve the text from the div contenteditable by using innerText in Chrome, IE, and Safari, and textContent in Firefox.

The problem is when I type newlines (by typing Enter key) inside the div contenteditable, the newlines don't appear in the textarea, all the text in the textarea appear in one line.

Here the source code, very simple :

<style type="text/css">

.textarea{  
overflow: hidden;
resize: none;
width: 100%;
white-space: pre-line;
border: solid #cccccc 1px ;
height: 34px;
}

</style>

<form style="width:500px;" method="post">

    Div contenteditable :
    <div class="textarea" contenteditable="true" onkeyup='copy_text_in_textarea(this);'></div>

    <br>Textarea :
    <textarea rows="2" class="textarea" id="textarea" name="textarea"></textarea>

</form>

<script type="text/javascript">

/*Function to reproduce div text in textarea :*/
function copy_text_in_textarea(this_contenteditable)
{       
        document.getElementById("textarea").value = this_contenteditable.textContent;       
}

</script>

You can try it with firefox here : https://jsfiddle.net/Ls6j041g/

So how to preserve the newlines for the textarea ?

Thank you in advance, cordially.

Answer:1

Is it possible to include the users' timezone if I want to send a push notification containing a datetime? Parse.Push.send({ where: query, // Set our Installation query data: { type: ...

Is it possible to include the users' timezone if I want to send a push notification containing a datetime? Parse.Push.send({ where: query, // Set our Installation query data: { type: ...

  1. parse push notification android
  2. parse push notification ios
  3. parse push notification android example
  4. parse push notification
  5. parse push notification swift
  6. parse push notification adapter
  7. parse push notification github
  8. parse push notification icon android
  9. parse push notification action
  10. parse push notification configuration
  11. parse push notifications web
  12. parse server push notification
  13. ios parse push notification payload
  14. parse send push notification
  15. parse javascript push notification
  16. parse server push notifications android
  17. parse server push notifications ios
  18. ionic parse push notifications
  19. parse cloud code send push notification
  20. how to use parse push notification

I know there are many techniques and methods to comparing two Strings, and find out if two Strings are equal or not. I want to do something like this: Var Str1 = "Hello How are you?"; var Str2 = "...

I know there are many techniques and methods to comparing two Strings, and find out if two Strings are equal or not. I want to do something like this: Var Str1 = "Hello How are you?"; var Str2 = "...

just wondering, what is the most efficient way to divide an array by a scalar? I can clearly loop over it, but efficiency is paramount in my case. common trivial way: var array_2 = [] var array_1 = ...

just wondering, what is the most efficient way to divide an array by a scalar? I can clearly loop over it, but efficiency is paramount in my case. common trivial way: var array_2 = [] var array_1 = ...

I have 2 types of a objects, a group, and an item. A group can have children which is either an array of groups or an array of items. I've ended up with a series of nested groups (which can be ...

I have 2 types of a objects, a group, and an item. A group can have children which is either an array of groups or an array of items. I've ended up with a series of nested groups (which can be ...