[以前のソリューションは Chrome と互換性がありませんでした (WebKit?)]
IF、BIG if、追加のコンテンツが入力の最後に追加されている場合、以下の演習で解決策が得られる場合があります。
<html>
<head>
<script>
function btnGoOnClick(ctrl)
{
//-- For this POC the text content is reset to 160 lines of dummy text -
//----------------------------------------------------------------------
ctrl.value = "";
for (var i = 0; i < 160; ++i)
{
ctrl.value += "dummy!\n";
}
//-- Then the carret is set to the last position -----------------------
//----------------------------------------------------------------------
if (ctrl.createTextRange)
{
//-- IE specific methods to move the carret to the last position
var textRange = ctrl.createTextRange();
textRange.moveStart("character", ctrl.value.length);
textRange.moveEnd("character", 0);
textRange.select();
}
else
{
//-- Mozilla and WebKit methods to move the carret
ctrl.setSelectionRange(ctrl.value.length, ctrl.value.length);
}
//-- For WebKit, the scroll bar has to be explicitly set ---------------
//----------------------------------------------------------------------
ctrl.scrollTop = ctrl.scrollHeight;
//-- Almost there: make sure the control has fucos and is into view ----
//----------------------------------------------------------------------
ctrl.focus();
ctrl.scrollIntoView(false);
}
</script>
</head>
<body>
<form name="form">
<input type="button" name="btnGo" value="Go!" onClick="btnGoOnClick(document.form.text);" />
<div style="height: 1000px"></div>
<textarea name="text" rows="80"></textarea>
</form>
</body>
</html>