문제

I have a textarea, and my onkeypress works just fine with hit.

However, if I keep trying to type the 256th character, my alert box eventually (2nd or 3rd time) also prints a little checkbox that I did not write. It says

[] Prevent this page from creating additional dialogs

I'm confused as to whether the browser (Firefox) or Javascript is doing that. Here is the code.

function warnOverDescLen()
{
var misc_text = document.forms["InvGenPayDonation"]["TransDesc"].value;

  if(255 < misc_text.length)
  {
    alert("You cannot enter more than 255 characters.");
    return false;
  }

  return true;
}
.
.
.
<textarea rows="4" cols="60" name="TransDesc" id="TransDesc" 
onkeypress="return warnOverDescLen();" ></textarea>
도움이 되었습니까?

해결책

The browser adds that functionality to prevent sites from annoying users with a barrage of (thread-locking) popup messages.

To avoid the issue, I would recommend you display the message ("You cannot enter more than 255 characters.") in a small label near the text box instead of using alert.

다른 팁

It is the browser, asking you if you want to disable repetitive alert messages. This is helpful in some development if, for example, an infinite loop is displaying alert messages. This gives a way to ignore that scenario. Otherwise it is a user aesthetic feature.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top