The <div> tag to be printed should bear the id="DivToPrint". Following HTML snippet depicts the same with comments(do read them carefully). The Button is used to execute the ‘PrintResults()’ function on Mouse click.
- Read the DIV tag with id="DivToPrint" and access its HTML content in a variable.
- Create an additional DIV tag which will have your custom HTML content to be printed. Add the custom HTML content to this DIV tag.
- Create a pop-up menu using ‘window.open()’. Open the document stream to this document and add the contents of both the DIV tags and close the stream. This Window when opened will open up the print window. On successful print operation, this window will terminate offering no user intervention with the window. You can remove the ‘window.close();’ code if you want this window to persist.
You can download the source code Here: