jQuery:100%高度iframe处于引导模式
我有一个php脚本,可以生成要打印的文档。我正试图让这个脚本以100%的宽度和高度进入Bootstrap4模式,这样客户端就可以检查内容,然后打印出来jQuery:100%高度iframe处于引导模式,jquery,iframe,bootstrap-4,bootstrap-modal,Jquery,Iframe,Bootstrap 4,Bootstrap Modal,我有一个php脚本,可以生成要打印的文档。我正试图让这个脚本以100%的宽度和高度进入Bootstrap4模式,这样客户端就可以检查内容,然后打印出来 <button type="button" id="print_modal" class="btn btn-primary" data-toggle="modal" data-target="#printmodal">Result</button> <div class="modal fade" id="printm
<button type="button" id="print_modal" class="btn btn-primary" data-toggle="modal" data-target="#printmodal">Result</button>
<div class="modal fade" id="printmodal">
<div class="modal-dialog" style="max-width:210mm !important">
<div class="modal-content">
<div class="modal-header">
<button class="btn btn-primary ml-1" id="print_btn">Tisk</button>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<div class="modal-body text-left" id="print_content">
<!-- IFRAME HERE -->
</div>
</div>
</div>
</div>
我需要像超时这样的东西来检查iframe填充后的高度,但我不知道怎么做
不工作:
在生成的iframe上使用onload参数:(返回0px-model FadeIn可能比iframe append慢…)
函数ifrhgh(){
变量iframehght=$(“#打印框”).contents().height();
}
此部分由按钮触发,该按钮也显示模式。所以模态应该在iframe加载之前打开
$('#print_modal').click(function () {
$('#print_content').html('<iframe src="./index.php?print" frameborder="0" scrolling="no" id="print_frame"></iframe>');
});
此部分由按钮触发,该按钮也显示模式。所以模态应该在iframe加载之前打开
$('#print_modal').click(function () {
$('#print_content').html('<iframe src="./index.php?print" frameborder="0" scrolling="no" id="print_frame"></iframe>');
});
已解决:
关键是在显示的上创建iframe。bs.modal
(成功加载后由modal触发的BS4事件),然后onload参数调用将iframe设置为content的ifrhgh()
函数
$(function () {
$('#printmodal').on('shown.bs.modal', function () {
$('#print_content').html('<iframe width="100%" onload="ifrhgh()" src="./index.php?print" frameborder="0" scrolling="no" id="print_frame"></iframe>');
});
});
function ifrhgh(){
var iframehght = $("#print_frame").contents().height();
$("#print_frame").height(iframehght);
}
$(函数(){
$('#printmodel').on('show.bs.modal',function(){
$(“#打印内容”).html(“”);
});
});
函数ifrhgh(){
变量iframehght=$(“#打印框”).contents().height();
$(“#打印框”)。高度(iframehght);
}
已解决:
关键是在显示的上创建iframe。bs.modal
(成功加载后由modal触发的BS4事件),然后onload参数调用将iframe设置为content的ifrhgh()
函数
$(function () {
$('#printmodal').on('shown.bs.modal', function () {
$('#print_content').html('<iframe width="100%" onload="ifrhgh()" src="./index.php?print" frameborder="0" scrolling="no" id="print_frame"></iframe>');
});
});
function ifrhgh(){
var iframehght = $("#print_frame").contents().height();
$("#print_frame").height(iframehght);
}
$(函数(){
$('#printmodel').on('show.bs.modal',function(){
$(“#打印内容”).html(“”);
});
});
函数ifrhgh(){
变量iframehght=$(“#打印框”).contents().height();
$(“#打印框”)。高度(iframehght);
}
这两个代码段完全相同。。。。fixedTry$(this).contents().height()
如果在您尝试测量时,作为此处容器的模态被隐藏,则高度将为零。这两个代码段是相同的sorry。。。。fixedTry$(this).contents().height()
如果在尝试测量时隐藏了此处的容器,则高度将为零。运气不好。这仅适用于动态除法、跨距..等,并且仅适用于“单击”触发器。使用iframe时,即使使用“click”也不起作用。这只适用于动态div、span..等,并且只适用于“click”触发器。使用iframe时,即使使用“单击”也不起作用
$(document).on("load","#print_frame",function(){
var iframeHeight = $(this).contents().height();
console.log(iframeHeight); // Check the console for that value.
$(this).height(iframeHeight);
});
$(function () {
$('#printmodal').on('shown.bs.modal', function () {
$('#print_content').html('<iframe width="100%" onload="ifrhgh()" src="./index.php?print" frameborder="0" scrolling="no" id="print_frame"></iframe>');
});
});
function ifrhgh(){
var iframehght = $("#print_frame").contents().height();
$("#print_frame").height(iframehght);
}