Link to home
Start Free TrialLog in
Avatar of pinaldave
pinaldaveFlag for India

asked on

printer page break and javascript iframe - help

Hello Experts,
I am trying to achive the page break for printer using one of the methods previously metnioned. in the Q
https://www.experts-exchange.com/questions/20169459/Printing-HTML-pages.html
https://www.experts-exchange.com/questions/21181900/Print-Page-Break-HTML-Page-Break.html

But when I print the javascript it does not insert the page break please guide me.

<style>
   .breakhere {page-break-after:always}
</style>

<iframe name="backFrame" id="backFrame" height="0" width="0"></iframe>
                  
                                                <input type=button value="Print" onClick="printMe(myGeneratedHTML)">

                                                      <script>
                                                      myGeneratedHTML='something<span class="breakhere"> &nbsp;</span>somethingagain'
                                                            function printMe(myGeneratedHTML) {
                                                            window.frames["backFrame"].document.write(myGeneratedHTML)
                                                            window.frames["backFrame"].document.close()  
                                                            setTimeout('window.frames["backFrame"].focus();window.frames["backFrame"].print();',100)
                                                            }
                                                      </script>


Regards,
---Pinal
Avatar of alain34
alain34
Flag of United Kingdom of Great Britain and Northern Ireland image

try to use these 2 changes

your style should be
page-break-before:always;

use div as opposed to span.
div is a block element, and page-break-before apply to block element, however I'm not sure span will work with it!
ASKER CERTIFIED SOLUTION
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pinaldave

ASKER

thank you very much mplungjan...
That worked like magic.
:)
---Pinal