Info

웹에서 특정 액션을 하는 버튼을 구현할 경우 인증번호를 받은 후 액션을 취해햐 하는 경우가 있다.
여러가지 방법들이 있겠지만 간단하게 버튼을 클릭하면 이동할 url을 받는 javascript 함수를 호출해서 제대로 된 인증번호를 입력한 경우 페이지 이동을 하는 방법을 알아보자.

Code

Javascript
function checkPassword(url, type) {
var correctPw = "";
if (type == 0) {
correctPw = "<? echo USER_APP_PW;?>";
}
else if (type == 1) {
correctPw = "<? echo RIDER_APP_PW;?>";
}
var inputPw = prompt(" ","");
if (inputPw == correctPw) {
location = url;
}
else {
alert(" ");
location = "#";
}
}
HTML
<button class="button" name="button" onclick="userappPasswordCheck([ ], [type])">
반응형

'Programming > JavaScript' 카테고리의 다른 글

Device Type Checker  (0) 2016.08.21