Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I came up with something similar to Shadow Wizard's effort which uses <code>oninput</code> to detect all forms of input (like pasting, drag/drop), not just keyboard input. It requires switching off the scrollbars of the textarea with the following CSS:</p> <pre><code>textarea { overflow: hidden; } </code></pre> <p>You might want to set <code>resize: none;</code> for browsers like Firefox 4 and Chrome. Also, Opera's wrapping doesn't break if there are no spaces, but it doesn't support <code>word-wrap: word-break;</code> properly so I'm not sure how you'd work around this. The JavaScript involves remembering the content of the textarea each time it changes and, if the text exceeds the size of the element, the change is reverted to the previous value:</p> <pre><code>var prev = "", tArea = document.getElementById("limit"); // Need to use onpropertychange event for IE8 and lower if ("onpropertychange" in tArea &amp;&amp; !("oninput" in tArea)) { tArea.onpropertychange = function () { // Only run code if value property changes if (window.event.propertyName == "value") this.oninput(); } } // oninput will fire for all types of input, not just keyboard tArea.oninput = function () { // Temporarily remove the onpropertychange event to prevent a stack overflow var opc = this.onpropertychange; this.onpropertychange = null; // Revert value if the text exceeds the size of the box if (this.scrollHeight &gt; this.offsetHeight) { this.value = prev; } prev = this.value; if (opc) this.onpropertychange = opc; } </code></pre> <p><b>Working demo: <a href="http://jsfiddle.net/37Jnn/" rel="nofollow">http://jsfiddle.net/37Jnn/</a></b> - tested in Firefox 4, IE8, Chrome 9, Opera 10.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload