我的要求是,点击一个按钮,一个 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">×</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 许可协议
很抱歉让你失望了,但默认情况下不能只在模态中显示 pdf。这不是预期的行为。即使使用
<iframe>
,您也无法在引导模式中呈现 pdf。此外,大多数在线提供的 hack 都不支持跨浏览器。更理想的方法是使用插件,我会给你一些链接,你可以使用它们来实现你想要的。1)结帐
PDFObject
JS,PDFObject 将 PDF 文件嵌入到 HTML 文档中。 链接。
用于 Bootstrap 的 Easy Modal 插件。 演示片段 和 网站
使用 jQuery 对话框模态弹出窗口。 演示。
希望它有所帮助。