Open modal on load page

This is an example that opens modal when loading web page

by fredd man

HTML

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<div class="mainPage">
<button class="openModal" data-content-id="modalContent1">Modal 1</button>
        <button class="openModal" data-content-id="modalContent2">Modal 2</button>
        <div class="modalMask modalHidden" id="modalMask"></div>
<div class="modalFrame modalHidden" id="modalFrame">
    <button class="dismissModal" id="dismissModal">x</button>
    <div id="modalContent"></div>
</div>
</div>

CSS

@import url(https://fonts.googleapis.com/css?family=Roboto:500,900italic,400italic,100,700italic,300,700,500italic,100italic,300italic,400);

body { background: #F5F5F5; color: #212121; font-family: 'Roboto'; font-size: 11pt; font-weight: 400; line-height: 1.64; height: 100vh; margin: 0; overflow: hidden; padding: 0; }

a:link, a:visited { color: #2962FF; }
a:hover, a:active { color: #2979FF; }

button { background: rgb(76, 142, 250);  border-radius: 2px; border: 0; box-sizing: border-box; color: #FFF; cursor: pointer; font-family: 'Roboto'; font-size: .875em; font-weight: 500; line-height: 1; padding: 10px 24px; transition: box-shadow 200ms cubic-bezier(0.4, 0, 0.2, 1); }
button:hover { box-shadow: 0 1px 3px rgba(0, 0, 0, .50); }
button:focus { outline: none; }
button.active { background: rgb(50, 102, 213); }

table { border-collapse: collapse; width: 100%; }
table th, table td { line-height: 1; padding: .5em 0; text-align: left; }
table th { color: #616161; font-weight: 500; }
table thead tr { border-bottom: 1px solid silver; }
table tbody tr { border-bottom: 1px solid #ddd; }

.mainPage { box-sizing: border-box; overflow: scroll; padding: 1em; height: 100vh; }
.mainPage h1 { margin-top: 0; }

.modalMask { background: #212121; opacity: .25; position: absolute; top: 0; bottom: 0; left: 0; right: 0; }

.modalFrame { background: #FAFAFA; box-shadow: 0 0 2em rgba(0,0,0,.5); bottom: 0; left: 2em; overflow: hidden; padding: 2em; position: absolute; right: 2em; top: 3em; transition: all .1s ease; }
#dismissModal { background: transparent; border: none; color: #616161; font-size: 1.5em; line-height: 1; padding: 0 .5em; position: absolute; right: 1em; text-shadow: none; top: 1em; }
#dismissModal:hover { box-shadow: none; color: #212121; }

#modalContent { margin: 0 2em 0 0; overflow-y: auto; padding: 0; }
#modalContent > h2 { margin-top: 0; }

.modalHidden { height: 0; top: 100vh !important; visibility: hidden; }
.contentTemplate { display: none; }

JavaScript

var $modalMask = {};
var $modalFrame = {};
var $modalContent = {};

var toggleModal = function() { 
    $modalMask.toggleClass("modalHidden");
    $modalFrame.toggleClass("modalHidden");
}

var updateModalContent = function(sourceId) {
    var content = "";
    if (sourceId) {
        content = $("#" + sourceId).html();
    }
    $modalContent.html(content);
}

$(document).ready(function() {
    $modalMask = $("#modalMask");
    $modalFrame = $("#modalFrame");
    $modalContent = $("#modalContent");
    
    $(".openModal").click(function() {
        $(this).addClass("active");
        updateModalContent($(this).data("contentId"));
        toggleModal();
    });
    $(".dismissModal").click(function() {
        toggleModal();
        updateModalContent();
        $(".openModal").removeClass("active");
    });   
});