PDF 文件将通过引导程序显示在对话框模式中

新手上路,请多包涵

我的要求是,点击一个按钮,一个 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>

原文由 Fresher 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 719
2 个回答

很抱歉让你失望了,但默认情况下不能只在模态中显示 pdf。这不是预期的行为。即使使用 <iframe> ,您也无法在引导模式中呈现 pdf。此外,大多数在线提供的 hack 都不支持跨浏览器。更理想的方法是使用插件,我会给你一些链接,你可以使用它们来实现你想要的。

1)结帐 PDFObject JS,

 <script src="https://github.com/pipwerks/PDFObject/blob/master/pdfobject.min.js"></script>

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

  1. 用于 Bootstrap 的 Easy Modal 插件。 演示片段网站

  2. 使用 jQuery 对话框模态弹出窗口。 演示

希望它有所帮助。

原文由 Nikhil Nanjappa 发布,翻译遵循 CC BY-SA 3.0 许可协议

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

 <embed src="sample.pdf" frameborder="0" width="100%" height="400px">

这对我有用

原文由 gabriel beltrami 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题