2016-08-23 11 views
-3

ポップアップダイアログボックスを印刷する必要があります。私は数回試しましたが、ポップアップダイアログボックスでウィンドウ全体を取得できましたが、ダイアログボックスだけを印刷する必要がありました。ポップアップダイアログボックスを印刷できません

ダイアログボックスを印刷できるソリューションが見つかりましたが、印刷中にテキストボックスに入力された値が表示されません。

以下のコードを参考にしてください。または、divの値をテキストボックス内の値で印刷するには参考にしてください。

これは、私がポップアップダイアログを印刷するために書いたコードです。

<script> 
    function PrintContent() 
    { 
     var DocumentContainer = document.getElementById('scorecard'); 
     var WindowObject = window.open("", "PrintWindow", 
     "width=750,height=650,top=50,left=50,toolbars=no,scrollbars=yes,status=no,resizable=yes"); 
     WindowObject.document.writeln('<!DOCTYPE html>'); 
     WindowObject.document.writeln('<html><head><title></title>'); 
     var str = "<style type='text/css' media='all'>"; 
     str = str + "MyStyles { text-align: center; }"; 
     str = str + "</style>"; 
     WindowObject.document.writeln(str); 
     WindowObject.document.writeln('</head><body>'); 
     WindowObject.document.writeln(DocumentContainer.innerHTML); 
     WindowObject.document.writeln('</body></html>'); 
     WindowObject.document.close(); 
     WindowObject.focus(); 
     WindowObject.print(); 
     WindowObject.close(); 
    } 
</script> 
+5

クールです。私たちに教えてくれてありがとう!新しい質問を書いてください。すぐに閉じられます。しかし、新しい質問をする前に[ヘルプセンターを見てください] – baao

+0

SOはコード作成サービスではありません。少なくともあなたの試みを見せてください。 –

答えて

-1

あなたが探しているものなら、ブートストラップモーダルボックスを使用できます。ここでコードは、あなたのhtmlファイルに貼り付け、それがあなたが望むものかどうかを確認するだけです。

<html> 
 
    <head> 
 
    <!-- Bootstrap Core CSS --> 
 
    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> 
 
    </head> 
 
    
 
    <body> 
 
     
 
     <div class="container"> 
 

 
    <!-- 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> 
 
      <h4 class="modal-title" style="color:#333;">Buy Membership</h4> 
 
     </div> 
 
     <div class="modal-body"> 
 
      <p style="color:#777;">You are not a premium member of Pagpry and thus you could use only limited images and features. Buy membership for more features and tools.</p> 
 
      <button type="button" class="btn btn-default"> <a href="#">Click Here to Know about Membership Plans.</a></button> 
 
     </div> 
 
     <div class="modal-footer"> 
 
      <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> 
 
     </div> 
 
     </div> 
 

 
    </div> 
 
     
 
      <script type="text/javascript" src="https://code.jquery.com/jquery-1.11.3.min.js"></script> 
 
    <script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> 
 
     
 
    <script> 
 
     $(document).ready(function(){ 
 
      alert('works'); 
 
      $('#myModal').modal(); 
 
      alert('works'); 
 
     }); 
 
     
 
     
 
    </script> 
 
    </body> 
 
</html>

0

ポップアップモーダル

HTML

<!-- Trigger/Open The Modal --> 
<button id="myBtn">Open Modal</button> 

<!-- The Modal --> 
<div id="myModal" class="modal"> 

    <!-- Modal content --> 
    <div class="modal-content"> 
    <span class="close">x</span> 
    <p>Some text in the Modal..</p> 
    </div> 

</div> 

CSS

/* The Modal (background) */ 
.modal { 
    display: none; /* Hidden by default */ 
    position: fixed; /* Stay in place */ 
    z-index: 1; /* Sit on top */ 
    left: 0; 
    top: 0; 
    width: 100%; /* Full width */ 
    height: 100%; /* Full height */ 
    overflow: auto; /* Enable scroll if needed */ 
    background-color: rgb(0,0,0); /* Fallback color */ 
    background-color: rgba(0,0,0,0.4); /* Black w/ opacity */ 
} 

/* Modal Content/Box */ 
.modal-content { 
    background-color: #fefefe; 
    margin: 15% auto; /* 15% from the top and centered */ 
    padding: 20px; 
    border: 1px solid #888; 
    width: 80%; /* Could be more or less, depending on screen size */ 
} 

/* The Close Button */ 
.close { 
    color: #aaa; 
    float: right; 
    font-size: 28px; 
    font-weight: bold; 
} 

.close:hover, 
.close:focus { 
    color: black; 
    text-decoration: none; 
    cursor: pointer; 
} 

JS

// Get the modal 
var modal = document.getElementById('myModal'); 

// Get the button that opens the modal 
var btn = document.getElementById("myBtn"); 

// Get the <span> element that closes the modal 
var span = document.getElementsByClassName("close")[0]; 

// When the user clicks on the button, open the modal 
btn.onclick = function() { 
    modal.style.display = "block"; 
} 

// When the user clicks on <span> (x), close the modal 
span.onclick = function() { 
    modal.style.display = "none"; 
} 

// When the user clicks anywhere outside of the modal, close it 
window.onclick = function(event) { 
    if (event.target == modal) { 
     modal.style.display = "none"; 
    } 
} 
関連する問題