如何在另一个 html 页面中打开一个 html 页面作为弹出窗口

问题描述 投票:0回答:2

我是 JavaScript 新手。现在我的主页中有一个重定向到其他 html 页面的链接,但我想在我的主页中显示一个具有响应能力的弹出窗口,并且某些样式(例如折叠角)。有没有办法在 javascript 中做到这一点。

谢谢你

javascript jquery html css
2个回答
3
投票

您可以简单地使用

<iframe>
在模态内容中显示另一个页面内容。

$(window).load(function(){
    $('#exampleModal').modal('show');
});
iframe {
    display:block;
    width:100%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js" integrity="sha384-smHYKdLADwkXOn1EmN1qk/HfnUcbVRZyYmZ4qpPea6sjB/pTJ0euyQp0Mk8ck+5T" crossorigin="anonymous"></script>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
  Launch demo modal
</button>

<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <iframe src="www.google.com"></iframe>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>


0
投票

它被称为“模态框”,具体操作方法如下:https://www.w3schools.com/howto/howto_css_modals.asp

至于样式,您可以简单地使用CSS。例如,对于链接示例中的圆角,只需添加例如

border-radius: 25px;
.modal-content
,这样你就有了

.modal-content {
  background-color: #fefefe;
  margin: auto;
  padding: 20px;
  border: 1px solid #888;
  width: 80%;
  border-radius: 25px;
}

具体对于折角,例子也很多,例如: https://codepen.io/brownerd/pen/lEHwLhttps://stackoverflow.com/a/55457088/9593181

© www.soinside.com 2019 - 2024. All rights reserved.