dallin
7/28/2016 - 9:05 PM

JS for Man

JS for Man

            <script>
            var windows = [];

            // Show the modal window
            function showModal(modal_id) {
                // Get the modal
                var modal = document.getElementById(modal_id);

                // Show the modal
                modal.style.display = "block";

                // Add it to the windows array
                windows.push(modal_id);
            }

            // Close modal window
            function closeModal(modal_id) {
                // Get the modal
                var modal = document.getElementById(modal_id);

                // Close the modal
                modal.style.display = "none";

                windows.pop();
            }

            // When the user clicks anywhere outside of the modal, close it
            window.onclick = function(event) {
                if (windows.length > 0) {
                    var modal = document.getElementById(windows[windows.length-1]);
                    if (event.target == modal) {
                        modal.style.display = "none";
                        windows.pop();
                    }
                }
            }
            </script>