最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - How to print popup window contents - Stack Overflow

matteradmin2PV0评论

I have tried the following:

<button onclick="window.print()" class="uk-button uk-float-left"><?php echo JText::_('COM_CSTUDOMUS_IMPRIMIR'); ?></button>

Also:

self.print()

window.focus();window.print()

When I click on print it shows the main window and the popup window in the page which is going to be printed. I only need the contents of the popup window.

I have tried the following:

<button onclick="window.print()" class="uk-button uk-float-left"><?php echo JText::_('COM_CSTUDOMUS_IMPRIMIR'); ?></button>

Also:

self.print()

window.focus();window.print()

When I click on print it shows the main window and the popup window in the page which is going to be printed. I only need the contents of the popup window.

Share Improve this question edited Mar 24, 2014 at 10:01 Victor York asked Mar 24, 2014 at 9:57 Victor YorkVictor York 1,6814 gold badges23 silver badges55 bronze badges 1
  • Are you using some kind of popup framework (i.e. fancybox, etc...)? – bastos.sergio Commented Mar 24, 2014 at 10:05
Add a ment  | 

2 Answers 2

Reset to default 5

This is an example of print popup:

<div class="contentSection">
    <div class="contentToPrint">
        <!-- content to be printed here -->
    </div>
</div>

<div class="contentSection">
    <a href="#" id="printOut">Print This</a>
</div>

<div class="contentSection termsToPrint">
    <h4>Terms & conditions</h4>
    <p>Management reserves the right to withdraw, amend or suspend this print job in the event of any unforeseen circumstances outside its reasonable control, with no liability to any third party.</p>
</div>

<script type="text/javascript" src="http://ajax.googleapis./ajax/libs/jquery/1.5.0/jquery.min.js"></script>

<script type="text/javascript">
    $(function(){
        $('#printOut').click(function(e){
            e.preventDefault();
            var w = window.open();
            var printOne = $('.contentToPrint').html();
            var printTwo = $('.termsToPrint').html();
            w.document.write('<html><head><title>Copy Printed</title></head><body><h1>Copy Printed</h1><hr />' + printOne + '<hr />' + printTwo) + '</body></html>';
            w.window.print();
            w.document.close();
            return false;
        });
    });
</script>
//popup page
   <html>
        <head>
        <title>Your popup</title>
        </head>
        <body>

        <h1>Pop</h1>
        <p>Print me</p>
        <a href="print.html" onclick="window.print();return false;">
            <img src="images/printer.png" height="32px" width="32px">
        </a>

        </body>
      </html>

//Main page
    <html>
        <head>
        <title>main</title>
        </head>
        <body>

        <h1>Pop & print</h1>
        <button onclick="pop();">Pop</button>
        <script type="text/javascript">
          var POP;
          function pop() {
            POP = window.open('popup.html', 'thePopup', 'width=350,height=350');
          }
        </script>

        </body>
      </html>
Post a comment

comment list (0)

  1. No comments so far