html - How to Show Javascript Modal Boxes Without Button? -


i have script open modal boxes javascript when user click button, want modify script, show modal boxes when page loaded specific parameter. example : http://domain.com/login?msg=incorrect password

any solution ?

<html> <head> <style> /* modal (background) */ .modal {     display: none; /* hidden default */     position: fixed; /* stay in place */     z-index: 1; /* sit on top */     padding-top: 100px; /* location of box */     left: 0;     top: 0;     width: 100%; /* full width */     height: 100%; /* full height */     overflow: auto; /* enable scroll if needed */     background-color: rgb(0,0,0); /* fallback color */     background-color: rgba(0,0,0,0.4); /* black w/ opacity */ }  /* modal content */ .modal-content {     position: relative;     background-color: #fefefe;     margin: auto;     padding: 0;     border: 1px solid #888;     width: 80%;     box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19);     -webkit-animation-name: animatetop;     -webkit-animation-duration: 0.4s;     animation-name: animatetop;     animation-duration: 0.4s }  /* add animation */ @-webkit-keyframes animatetop {     {top:-300px; opacity:0}      {top:0; opacity:1} }  @keyframes animatetop {     {top:-300px; opacity:0}     {top:0; opacity:1} }  /* close button */ .close {     color: white;     float: right;     font-size: 28px;     font-weight: bold; }  .close:hover, .close:focus {     color: #000;     text-decoration: none;     cursor: pointer; }  .modal-header {     padding: 2px 16px;     background-color: #5cb85c;     color: white; }  .modal-body {padding: 2px 16px;}  .modal-footer {     padding: 2px 16px;     background-color: #5cb85c;     color: white; } </style> </head> <body>  <h2>animated modal header , footer</h2>  <!-- trigger/open modal --> <button id="mybtn">open modal</button>  <!-- modal --> <div id="mymodal" class="modal">    <!-- modal content -->   <div class="modal-content">     <div class="modal-header">       <span class="close">×</span>       <h2>modal header</h2>     </div>     <div class="modal-body">       <p>some text in modal body</p>       <p>some other text...</p>     </div>     <div class="modal-footer">       <h3>modal footer</h3>     </div>   </div>  </div>  <script> // modal var modal = document.getelementbyid('mymodal');  // button opens modal var btn = document.getelementbyid("mybtn");  // <span> element closes modal var span = document.getelementsbyclassname("close")[0];  // when user clicks button, open modal  btn.onclick = function() {     modal.style.display = "block"; }  // when user clicks on <span> (x), close modal span.onclick = function() {     modal.style.display = "none"; }  // when user clicks anywhere outside of modal, close window.onclick = function(event) {     if (event.target == modal) {         modal.style.display = "none";     } } </script>  </body> </html> 

this demo of code : http://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_modal2

try adding

document.addeventlistener('domcontentloaded', function() {     modal.style.display = "block"; }); 

what is:

  • an event happen, when dom content has been loaded.
  • when happens, fire function you've defined
  • your modal shown when automatically

Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -