activar automáticamente modal bootstrap

publicado por: Anonymous

buenos dias tengo un pequeño codigo html para llamar una ventana modal
al cargar y hago alerts antes y despues y los manda excepto el modal

  <script type="text/javascript">
function redireccionar(){
  alert("1");
  document.getElementById('id01').style.display='active';
  alert("p2");
} 
setTimeout ("redireccionar()", 1000); //tiempo expresado en milisegundos
</script>

probe de esta manera

<button id="id01" type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>

y esta otra

<button onclick="document.getElementById('id01').style.display='none'" type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>

este es el div

<div id="id01" class="modal fade" role="dialog">
  <div  class="modal-dialog">

    <!-- Modal content-->
    <div  class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Modal Header</h4>
      </div>
      <div id="id01" class="modal-body">
        <img class="third-slide" src="../img/cat_001.png" alt="Third slide">
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>

  </div>
</div>

solución

Funciona si simplemente usas el id correcto asi:

_x000D_

_x000D_

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">_x000D_
_x000D_
<!-- jQuery library -->_x000D_
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>_x000D_
_x000D_
<!-- Latest compiled JavaScript -->_x000D_
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>_x000D_
_x000D_
<script type="text/javascript">_x000D_
function redireccionar(){_x000D_
  alert("1");_x000D_
  document.getElementById('id01').style.display='active';_x000D_
  $("#id01").trigger("click");_x000D_
} _x000D_
setTimeout ("redireccionar()", 1000); //tiempo expresado en milisegundos_x000D_
</script>_x000D_
_x000D_
<button id="id01" type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>_x000D_
<div id="myModal" class="modal fade" role="dialog">_x000D_
  <div  class="modal-dialog">_x000D_
_x000D_
    <!-- Modal content-->_x000D_
    <div  class="modal-content">_x000D_
      <div class="modal-header">_x000D_
        <button type="button" class="close" data-dismiss="modal">&times;</button>_x000D_
        <h4 class="modal-title">Modal Header</h4>_x000D_
      </div>_x000D_
      <div id="id01" class="modal-body">_x000D_
        <img class="third-slide" src="../img/cat_001.png" alt="Third slide">_x000D_
      </div>_x000D_
      <div class="modal-footer">_x000D_
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>_x000D_
      </div>_x000D_
    </div>_x000D_
_x000D_
  </div>_x000D_
</div>

_x000D_

_x000D_

_x000D_

Respondido por: Anonymous

Leave a Reply

Your email address will not be published. Required fields are marked *