HTML, JavaScript And CSS Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingHTML, JavaScript And CSS Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old January 19th, 2005, 05:16 AM
thayalan44 thayalan44 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 29 thayalan44 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 10 m 55 sec
Reputation Power: 0
Printing a page using javascript

Can you show me sample codes using javascript to print a selected area in a document onto an A4 size paper?
Thanks in advance!

Reply With Quote
  #2  
Old January 19th, 2005, 07:05 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
ASP Free God 46th Plane (27500 - 27999 posts)
 
Join Date: Sep 2004
Location: Israel
Posts: 27,628 Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)  Folding Points: 372965 Folding Title: Super Ultimate Folder - Level 1Folding Points: 372965 Folding Title: Super Ultimate Folder - Level 1Folding Points: 372965 Folding Title: Super Ultimate Folder - Level 1Folding Points: 372965 Folding Title: Super Ultimate Folder - Level 1Folding Points: 372965 Folding Title: Super Ultimate Folder - Level 1Folding Points: 372965 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 2 Weeks 2 h 23 m 57 sec
Reputation Power: 1902
to print only part of the document, you'll have to copy the desired elements into new browser window and print it using javascript. first, you have to give unique id to all elements, then you can use such code:
Code:
  <script language="javascript">
    function PrintParts(arrElementNames)
    {
     var objWindow=window.open("about:blank", "print", "left=0, top=0, width=10, height=10, toolbar=no, scrollbars=no");
     var strHtml="<html>";
     strHtml += "<head>";
     strHtml += "</head>";
     strHtml += "<body>";
     for (var i=0; i<arrElementNames.length; i++)
     {
  	  var element=document.getElementById(arrElementNames[i]);
  	  strHtml += element.innerHTML;
     }
     strHtml += "</body>";
     strHtml += "</html>";
     objWindow.document.write(strHtml);
     objWindow.document.close();
     objWindow.print();
     objWindow.close();
    }
  </script>
  <div id="element1">I'm the first element. you can put here whatever you want.</div>
  <div id="element2"><form>
  you can also have forms and <input type="text" /> text boxes.</form>
  </div>
  <div id="element3">this for example won't be printed.</div>
  <input type="button" value="Print" onclick="PrintParts(new Array('element1', 'element2'));" />
  


whatever elements you pass to the function as part of the array would be printed.

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingHTML, JavaScript And CSS Help > Printing a page using javascript


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT