Javascript例程-打印/但不遵循CSS大小或没有打印类

时间:2019-05-27 22:41:12

标签: javascript wordpress printing-web-page

我有一个自定义插件,我需要用户在其中打印模式(灯箱)对话框。打印例程可以打印材料...但是它不遵循页面上CSS的大小。例如,徽标图像,CSS代码将其设置为以60 x 60像素显示。根据用户加载到帐户中的内容,打印内容会完全放大到完整大小。介质的大小不可控。不过,通过页面的CSS代码和文档句柄进行的格式设置应按指定显示,而不能显示。为什么?

该例程还忽略CSS代码以跳过打印某些DIV部分。如果我使用windows.print,但不使用mywindow.print(),则此方法有效。如代码中所示。再次为什么?

曾尝试过不同的打印请求,包括“ windows.print”,它确实跳过了定义为不打印的DIV部分……它还希望打印整个页面,而不仅仅是模式框。目前,我已关闭了在移动设备上进行打印的功能。那什么也没做。

{

    if(IsMobileCard()==false)
     {
     var mywindow = window.open('', 'PRINT', 'height=400,width=600');

     mywindow.document.write('<html><head><title>' + document.title  + '</title>');
     mywindow.document.write('</head><body >');
     mywindow.document.write('<h1>' + document.domain + '</h1>');
     mywindow.document.write(document.getElementById('modal-modalcontent' + ModalBoxId).innerHTML);
     mywindow.document.write('</body></html>');

     mywindow.document.close(); // necessary for IE >= 10
     mywindow.focus(); // necessary for IE >= 10*/

     mywindow.print();
     mywindow.close();

    }
    else
      Alert('Unavailable on Mobile');

    return true;
   //window.print(); 

}

模态(灯箱)对话框的示例在这里:

<div id="<?php echo 'CardModal' . $CardIndex; ?>" class="modal">'
<span class="close cursor" onclick="closeModal<?php echo $CardIndex; ?>()">&times;</span> 
<div id="modal-modalcontent<?php echo $CardIndex; ?>" class="modal-content">
<div class="modalNameArea">
  <div class="modalBusinssLogo">
  <?php
  if(strlen($LogoPath)>3)
    {
  ?>
   <img src="<?php echo $LogoPath?>" alt="Listing Photo">
  <?php
    }
   else
    { 
    ?>
     <img src = "defaultlogo.png" alt="Listing Logo"" />
    <?php
    }
   ?>
  </div>
  <div class="modalcardBusinessName-expanded"><?php echo $MemberData['BusinessName']; ?><hr /></div> 
</div>

<div class="modalConnectionGroup">
 <div class="modalConnectArea5">
 <hr>
   <div id="modal-Print" class="noPrint"><button class = "PopupButton noPrint" id="btnPrint"  onclick="SetupPrint(<?php echo $CardIndex; ?>)" >Print Card</button></div>
 </div>
</div>


<div>
<div>

CSS代码在这里:

@media print 
{
.noPrint  { display:none; }  
}

0 个答案:

没有答案