script 를 이용한 안내 창 (Alert) 커스텀하여 출력하기

반응형

아래 소스를 적당히 수정하여 사용합니다.

 

<html lang="ko">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Custom Alert</title>
    <style>
        /* Custom alert box styling */
        .alert-overlay {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.5);
            display: flex;
            justify-content: center;
            align-items: center;
            z-index: 9999; /* High z-index to ensure it is on top */
        }
        .alert-box {
            background: white;
            padding: 20px;
            border-radius: 5px;
            text-align: center;
            width: 400px;
            height: 250px;
            display: flex;
            flex-direction: column;
            justify-content: center;
        }
        .alert-box h1 {
            margin-top: 0;
        }
        .alert-box p {
            margin: 20px 0;
            font-size: 13px;
            color: #111111;
        }
        .alert-box button {
            width: 100px; /* Set fixed width */
            margin: 0px auto 0px; /* Center horizontally */
            padding: 10px;
            border: none;
            background: #007BFF;
            color: white;
            border-radius: 5px;
            cursor: pointer;
        }
        .alert-box button:hover {
            background: #0056b3;
        }
    </style>
</head>
<body>
    <div id="alertOverlay" class="alert-overlay" style="display: none;">
        <div class="alert-box">
            <h1>데모 페이지 로그인 정보</h1>
            <p>계정 : <font size="3" color="blue">sysdocu</font><br>
비밀번호 : <font size="3" color="blue">12345678</font><br><br>
* 다른 사용자와의 중복 테스트로 오작동이 일어날 수 있습니다.<br>
* 테스트를 마친 후 데이터를 삭제해 주시기 바랍니다.</p>
            <button onclick="closeAlert()">확인</button>
        </div>
    </div>
    <script>
        function showAlert() {
            document.getElementById('alertOverlay').style.display = 'flex';
        }

        function closeAlert() {
            document.getElementById('alertOverlay').style.display = 'none';
        }

        // Show the alert when the page loads
        window.onload = showAlert;
    </script>
</body>
</html>

 

반응형

댓글()