Results 1 to 3 of 3

Thread: Print version

  1. #1
    Join Date
    Dec 2005
    Posts
    133
    Thanks
    23
    Thanked 0 Times in 0 Posts

    Default Print version

    I have a js script that creates a print version for all my pages.
    I add an ID where there is content and this is what I will see on the print versio page.
    Now the problem is: I want to print 2 elements from my page.
    I get some error
    Can someone look at it pls and help me out

    ORIGINAL CODE:
    Code:
    <script>function print1() {
    		var pre='<html><head>' +
    		'<style>body,  div, table{font-family : arial ; }</style>' +
    		'</head><body>'
    		var post="</body></html>"
    		var gwin=open('print.html','hi','width=730,height=500,menubar,scrollbars')
    		var  obj = pre + document.getElementById("scroll1").innerHTML + post ;
    		gwin.document.write(obj) ;
    		gwin.document.close()  ;
    		gwin.focus 
    		
    		}
    	
    </script>
    
      <div  id="scroll1">text to be printed</div>
    <a href="Javascript:print1()" > Print Version</a>
    now I want to add another id to another div cause I also want it to be printed.
    I did this but it doesnt work:

    Code:
    <script>function print1() {
    		var pre='<html><head>' +
    		'<style>body,  div, table{font-family : arial ; }</style>' +
    		'</head><body>'
    		var post="</body></html>"
    		var gwin=open('print.html','hi','width=730,height=500,menubar,scrollbars')
    		var  obj = pre + document.getElementById("scroll1").innerHTML + post ;
                                var  obj = pre + document.getElementById("scroll2").innerHTML + post ;
    
    		gwin.document.write(obj) ;
    		gwin.document.close()  ;
    		gwin.focus 
    		
    		}
    	
    </script>
    <div  id="scroll2">image to be printed</div>
    <div  id="scroll1">text to be printed</div>
    <a href="Javascript:print1()" > Print Version</a>
    WHAT IS WRONG WITH IT??
    Last edited by Snookerman; 05-19-2009 at 11:11 AM. Reason: added [code] tags

  2. #2
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    Try this

    Code:
    function print1(){
                    var pre = '<html><head>' +
                    '<style>body,  div, table{font-family : arial ; }</style>' +
                    '</head><body>';
                    var post = "</body></html>";
                    var gwin = open('print.html', 'hi', 'width=730,height=500,menubar,scrollbars');
                    var obj = pre + document.getElementById("scroll1").innerHTML + "<br/>" + document.getElementById("scroll2").innerHTML + post;                
                    gwin.document.write(obj);
                    gwin.document.close();
                    gwin.focus();
    		gwin.print();                
                }
    But I feel that you can make this function more usable.

  3. #3
    Join Date
    Dec 2005
    Posts
    133
    Thanks
    23
    Thanked 0 Times in 0 Posts

    Default

    thank you
    for the meantime it does the job!!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •