J'ai texbox dans ma page et j'essaie d'obtenir la longueur de la zone de texte. Je sais comment obtenir la longueur dans IE, mais le code suivant ne fonctionne pas dans FF et chrome.window.getselection() ne fonctionne pas en FF et chrome
<!DOCTYPE html>
<html>
<head>
<script>
function myFunction(obj)
{
alert("mouse up");
var r=window.getSelection().createRange();
alert(r.text.length);
}
</script>
</head>
<body>
<textarea id="myArea" cols="30" spellcheck="false" onmouseup=myFunction(this)>Select some text within this field.</textarea>
</body>
</html>
Voir ici: http://stackoverflow.com/a/5072684/1296553 –
Dupliquer de [window.getSelection() de textarea ne fonctionne pas dans firefox?] (Http://stackoverflow.com/questions/20419515/window-getselection-of-textarea-not-working-in-firefox), qui a de meilleures réponses. [window.getSelection ne fonctionne pas sur les textareas dans Firefox est un bug fabuleusement vieux dans FF] (https://bugzilla.mozilla.org/show_bug.cgi?id=85686). –