Home > Mobile >  Print Content Of Bootstrap Modal Window
Print Content Of Bootstrap Modal Window

Time:05-26

I have a table in laravel with different data in the lines and a button that opens a mondal with the information, but when I open the modal and click on the button inside the modal to print it does not work.

                            <div >

                                <button type="button"  data-dismiss="modal">Close</button>
                                <button id="btnPrint" type="button" >Print</button>
                                

                                <script>
                                document.getElementById("btnPrint").onclick = function() {
                                    printElement(document.getElementById("printThis"));
                                }

                                function printElement(elem) {
                                    var domClone = elem.cloneNode(true);

                                    var $printSection = document.getElementById("printSection");

                                    if (!$printSection) {
                                        var $printSection = document.createElement("div");
                                        $printSection.id = "printSection";
                                        document.body.appendChild($printSection);
                                    }

                                    $printSection.innerHTML = "";
                                    $printSection.appendChild(domClone);
                                    window.print();
                                }
                                </script>

CodePudding user response:

<button id="btnPrint"type="button" >Print

Simply add onclick="window.print()" in your button tag and remove rest of script.

Please let me know if it works.

CodePudding user response:

Add, but not show nothing to print.

  • Related