How to print the contents of a page with Bootstrap and Jquery?

Asked

Viewed 5,964 times

3

I would like to add a Bootstrap button to invoke the printing of a page’s content, I got this example, but it works from a link, see: Example

The code places the link at the top of the page, I also saw an example right here, in this link Stackoverflow example, but would not like to open the page with content again, simply click the button, call the print box and print as in the first cited example.

The code of the first example is this:

$(document).ready(function() {
    $('#container').prepend('Click aqui para imprimir');
    $('a#print').click(function() {
        window.print();
        return false;
    });
});

1 answer

5


If your goal is to have a button that uses the bootstrap classse and only usebtn btn-primary for example, and if you do not want to open in new open and only remove the target_blank, from what I understand would be something like this:

        document.getElementById('btn').onclick = function() {
          window.print();
        };
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">

<body>
  <div id="sua_div">Essa é a DIV</div>
  <button id="btn" class="btn btn-primary">Clique para imprimir</button>
</body>

  • Hello @Gabriel Rodrigues, thank you so much for the collaboration, was of great help.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.