2

Browsers inserts automatically a word break when text reaches the end of the box. I would like to make this "invisible" to real \n.

Here is what I have tired: http://jsbin.com/uraneq/1/edit

Example: enter image description here

  • 10
    No, they don't automatically insert a line break (you can see for yourself by enlarging the textarea after the text has wrapped -- it will unwrap). The question is also very unclear. – Jon Dec 12 '12 at 13:15
  • If I type a text and if it reaches the end of the box the next word will appear in the next line (unless I pressed enter) I would like to detect this, and convert to real line breaks. –  Dec 12 '12 at 13:19
  • 1
    Why? Text layout should be performed when laying the text out, not when accepting input. – Jon Dec 12 '12 at 13:28
  • What you want is to save the text wrapped as it shows in the textarea? If this is what you are looking for, why? – Diego Dec 12 '12 at 13:29
  • 1
    why do you need that? Possibly there is better way to solve your problem. Making what you want is not a simple task as there is no any symbol that could be replaced. – Viktor S. Dec 12 '12 at 13:31
  • If your textarea uses a fixed-width font like on the screenshots, just add a `\n` every *n* characters. See http://stackoverflow.com/q/1772941/825789 – bfavaretto Dec 12 '12 at 13:32
  • because I would like to generate a SVG from this text and I need to know, where the text does not fit the fixed size area. –  Dec 12 '12 at 13:32
  • @bfavaretto They dont have a fixed length. –  Dec 12 '12 at 13:34
  • @bfavaretto, it is much complex. Browsers don't cut the word in two. If the textarea line is for 10 chars and you start a (long) word at 8th pos, it will be shown entirely in the next line. – Diego Dec 12 '12 at 13:34

2 Answers2

0

​ will not be auto inserted by the browser itself so you cannot match it in auto broken text.

however.. you can match line length to see when there might be a possible linebreak (in case you use a block font)

GottZ
  • 4,824
  • 1
  • 36
  • 46
0

You can try to use wrap="hard" attribute for TEXTAREA element. Older browsers support physical value which has similar meaning as hard (but is invalid at least in HTML5).

Marat Tanalin
  • 13,927
  • 1
  • 36
  • 52
  • "If you set it to physical the text is submitted exactly as it appears on the screen - linebreaks included." thats right, but how can I get that value? –  Dec 12 '12 at 13:47
  • For example, in PHP, posted data is in `$_POST` array. In client side, it's unlikely possible to retrieve such modified data. Take into account that `physical` is nonstandard value anyway, and `hard` should be used instead. – Marat Tanalin Dec 12 '12 at 13:51