I use JQuery UI and Bootstrap , so I ran into this problem, and I think this is a conflict between them, as in the normal case the text area or input file is edited by nature, but I made this decision after testing all of the above answers, but none of them allowed cross-browser support for all major browsers , but I solved it and I like to share my solution with which you can use it. input text and text box
(Tested on the desktop: IE (all versions), Chrome, Safari, Windows Edge, Firefox, Visual Studio Cordoba Ripple Viewer on Windows and Visual Studio Cordoba Windows 10 Store App)
(tested on mobile devices: Chrome, Firefox, Android Internet Browser and Visual Studio. Cordova application for Android and Visual Studio Cordova Windows 8 + 8.1 + 10 Phone App)
This is the HTML:
<textarea contenteditable id="textarea"></textarea>
This is the CSS code:
textarea { -webkit-user-select: text !important; -khtml-user-select: text !important; -moz-user-select: text !important; -ms-user-select: text !important; user-select: text !important; background-color:#fff !important; color:#733E27 !important; }
This is the jQuery code in the finished document
$("textarea").click(function() { setTimeout(function(){ $("textarea").focus(); //add this if you are using JQuery UI (From The Solutions Above) $("textarea").enableSelection(); var val = $("textarea").val(); if (val.charAt(val.length-1) !== " " && val.length !== 1) { alert(val.length); val += " "; } $("textarea").val(val); }, 0); }); if (navigator.userAgent.indexOf('Safari') !== -1 || navigator.userAgent.indexOf('Chrome') !== -1) { //alert('Its Safari or chrome'); $("textarea").onfocus(function(e) { setTimeout(function(){ var end; if ($("textarea").val === "") { end = 0; } else { end = $("textarea").val.length; } if ($("textarea").setSelectionRange) { var range = document.getElementById('textarea').createTextRange(); if (range) { setTimeout(range, 0, [end, end]); } else { // IE style var aRange = document.getElementById('textarea').createTextRange(); aRange.collapse(true); aRange.moveEnd('character', end); aRange.moveStart('character', end); aRange.select(); } } e.preventDefault(); return false; }, 0); }); }
You can test it in your web application www.gahwehsada.com
Emad Morris Zedan Mar 15 '16 at 23:59 2016-03-15 23:59
source share