프로그래밍/자바스크립트
JAVASCRIPT : INPUT 아이디, 패스워드 자동완성(AUTOCOMPLETE) 제거 방법
재우니
2022. 8. 9. 10:57
JAVASCRIPT : INPUT 아이디, 패스워드 자동완성(AUTOCOMPLETE) 제거 방법
<h1>Prevent Chrome etc. from autofilling in password and login fields.</h1>
<h2>using readonly-attribute and remove it on focus (touch, tab, click)</h2>
<h2>(now with fix for mobile Safari to show virtual keyboard)</h2>
<form>
<label for="email">E-Mail</label>
<input id="email" readonly type="email" onfocus="if (this.hasAttribute('readonly')) { this.removeAttribute('readonly');
// fix for mobile safari to show virtual keyboard
this.blur(); this.focus(); }" />
<br/>
<label for="pw">Password</label>
<input id="pw" readonly type="password" onfocus="if (this.hasAttribute('readonly')) { this.removeAttribute('readonly');
// fix for mobile safari to show virtual keyboard
this.blur(); this.focus(); }" />
<br/>
<input type="submit" value="Go!" />
</form>
테스트
https://jsfiddle.net/danielsuess/n0scguv6/
활용해 보자!!
<div class="form-group">
<input id="UserName" name="UserName" readonly type="text" maxlength="20" onkeyup = "RemoveKor(this)" class="form-control" placeholder="아이디 입력" onfocus="if (this.hasAttribute('readonly')) { this.removeAttribute('readonly'); this.blur();this.focus(); }" />
</div>
<div class="form-group">
<input id="Password" name="Password" readonly type="password" maxlength="20" class="form-control" placeholder="비밀번호 입력" onfocus="if (this.hasAttribute('readonly')) { this.removeAttribute('readonly'); this.blur();this.focus(); }" />
</div>
/**********************************************************************************************
* 작성목적 : 한글제거
**********************************************************************************************/
function RemoveKor(obj) {
var regexp = /[ㄱ-ㅎ|ㅏ-ㅣ|가-힝]/g; // 한글제거
obj.value = obj.value.replace(regexp, '');
}
참고 사이트