Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script type="text/javascript">
- function PrintDiv(id) {
- var data=document.getElementById(id).innerHTML;
- var myWindow = window.open('', 'testing', 'height=800,width=1000');
- myWindow.document.write('<html><head><title>testing</title>');
- /*optional stylesheet*/ //myWindow.document.write('<link rel="stylesheet" href="main.css" type="text/css" />');
- myWindow.document.write('</head><body >');
- myWindow.document.write(data);
- myWindow.document.write('</body></html>');
- myWindow.document.close(); // necessary for IE >= 10
- myWindow.onload=function(){ // necessary if the div contain images
- myWindow.focus(); // necessary for IE >= 10
- myWindow.print();
- myWindow.close();
- };
- }
- </script>
- <div id="myDiv">
- This will be printed.
- <img src="image.jpg"/>
- </div>
- <div>
- This will not be printed.
- </div>
- <div id="anotherDiv">
- Nor will this.
- </div>
- <input type="button" value="Print Div" onclick="PrintDiv('myDiv')" />
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement