通过bootstrap在对话框模态上显示的PDF文件

Fre*_*her 6 javascript jquery twitter-bootstrap

我的要求是,点击一个按钮,pdf文件应显示在对话框模式上.请帮忙!

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
  <h2>View PDF</h2>
  <!-- Trigger the modal with a button -->
  <button type="button" href="A - Cover Page.pdf" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">A - Cover Page</button>
  <!-- Modal -->
  <div class="modal fade" id="myModal" 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>
    </div>        
        <div class="modal-body">
          <p>Some text in the modal.</p>
        </div>
      </div>
    </div>
  </div>
 </div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

Nik*_*ppa 12

很抱歉让你失望,但默认情况下,不能只在模式中显示pdf.这不是预期的行为.即使使用<iframe>,也无法在引导程序模式中呈现pdf.此外,大多数在线提供的黑客都不支持跨浏览器.更理想的方法是使用相同的插件,我会给你几个使用的链接,你可以实现你想要的.

1)结帐PDFObjectJS,

<script src="https://github.com/pipwerks/PDFObject/blob/master/pdfobject.min.js"></script>
Run Code Online (Sandbox Code Playgroud)

PDFObject将PDF文件嵌入到HTML文档中.链接.

2)用于Bootstrap的Easy Modal插件.演示片段和网站

3)使用jQuery Dialog Modal弹出窗口.演示.

希望它有所帮助.


小智 11

<div class="modal fade" id="modal-agreement">
  <div class="modal-dialog modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-body">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
        <object type="application/pdf" data="path/to/pdf" width="100%" height="500" style="height: 85vh;">No Support</object>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
Run Code Online (Sandbox Code Playgroud)

  • 一点点解释会有所帮助.您的代码如何回答这个问题? (9认同)

小智 9

您还可以将pdf嵌入模态中.像这样:

<embed src="sample.pdf" frameborder="0" width="100%" height="400px">
Run Code Online (Sandbox Code Playgroud)

这对我有用