Thursday, October 8, 2015

How to print a div

You can print any div by using this code. Just copy and pest this code in your html page what I given below:
<html>
<head> 
<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.1.min.js" > </script> 
<!-- You should use JavaScript--> 
<script type="text/javascript">

    function PrintElem(elem)
    {
        Popup($(elem).html());
    }

    function Popup(data) 
    {
        var mywindow = window.open('', 'my div', 'height=400,width=600');
        mywindow.document.write('<html><head><title>my div</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.focus(); // necessary for IE >= 10

        mywindow.print();
        mywindow.close();

        return true;}
</script>
</head>
<body>
<div id="mydiv"> <!-- This is the div what you want to print -->
    Hello world. I want to printed by your pronter. So print me now. 
Hello world. I want to printed by your pronter. So print me now. 
Hello world. I want to printed by your pronter. So print me now. 
   </div>
<div>
    This will not be printed.
</div>
<div id="anotherdiv">
    Nor will this.
</div>
<input type="button" value="Print Div" onclick="PrintElem('#mydiv')" />

</body>
</html>
 
Just try your self. Thank you 

Related Posts:

  • How to print a div You can print any div by using this code. Just copy and pest this code in your html page what I given below: <html> <head> <script … Read More
  • css 1 this is css post … Read More
  • HTML-5 You can write HTML code in word pad, notepad, notepad++, DW etc. But I like to use Notepad++. At first you have to take a new page in HTML format (i… Read More
  • HTML 5 HTML5 is the latest version of HTML. You can make your site more easily by HTML5. Here are some code is rejected  from HTML and some code is a… Read More
  • How to write html code? You can write HTML code in word pad, notepad, notepad++, DW etc. But I like to use Notepad++.At first you have to take a new page in HTML format (ind… Read More

0 comments:

Post a Comment