Different links in Bootstrap

Asked

Viewed 2,023 times

0

I have a lightbox in bootstrap and would like to know how I do for each time that click on a href link he open the content that is in href="" of each link?

Below my code if anyone can help me.

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title></title>
    <link rel="stylesheet" href="">

  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>   
</head>
<body>
<a href="http://www.terra.com.br">Link 1 / Iframe</a>
<a href="http://www.uol.com.br">Link 2 / Iframe</a>



    <!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="myModalLabel">Modal title</h4>
      </div>
      <div class="modal-body">
          <iframe src="/user/dashboard" width="300" height="380" frameborder="0" allowtransparency="true"></iframe>  
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>
    <!-- /.modal-content -->
  </div>
  <!-- /.modal-dialog -->
</div>
<!-- /.modal -->
</body>
</html>
  • Do you want to open this link where? in modal?

  • Yes it would be in modal

  • It was missing to put the ID in your modal <div id="#loadURL" class="modal-body" > <iframe src="/user/Dashboard" width="300" height="380" frameborder="0" allowtransparency="true" id="myModal"> </iframe> </div> Note 1.: Do not reply to your post instead edit it. Obs2.: You will not need inframe, direct click on the Modal body. obs3.: Fix your onclick, single quotes cannot stay inside single quotes.<a &#xA; data-toggle="modal" &#xA; href="#myModal" &#xA; onclick="$('#loadURL').load('http://terra.com.br')">Link 1 / Iframe&#xA;</a>

1 answer

0

You can do it like this.

<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title></title>
  <link rel="stylesheet" href="">

  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  <script>
    var loadURL = function (url) {
      console.log($('#myInframe').attr({
        width: 300,
        height: 380,
        frameborder: 0,
        allowtransparency: true,
        src: url
      })
      )
    }
  </script>
</head>

<body>
  <a data-toggle="modal" href="#myModal" onclick='loadURL("http://terra.com.br")'>Link 1 / Iframe
  <a data-toggle="modal" href="#myModal" onclick='loadURL("http://superanimes.com")'>Link 1 / Iframe
  
</a>



  <!-- Modal -->
  <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
          <h4 class="modal-title" id="myModalLabel">Modal title</h4>
        </div>
        <div class="modal-body">
          <iframe id="myInframe" name="myFrame" src="/user/dashboard" width="300" height="380" frameborder="0" allowtransparency="true"></iframe>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div>
      <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
  </div>
  <!-- /.modal -->

  
</body>

</html>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.