print the part of the page without opening new window

Javascript coding ..

Moderators: macek, egami, gesf

snsanju
New php-forum User
New php-forum User
Posts: 42
Joined: Thu Aug 04, 2005 1:35 am
Location: Bangalore, India
Contact:

print the part of the page without opening new window

Postby snsanju » Mon Feb 06, 2006 3:39 am

Hello guys,

is there any way to print only contents(small part) of a whole page, instead of printing the whole page without opening the new popup or page or new window.

i tried the following but still its opening the new window asking the print

Code: Select all

<html>
<head><title>print</title>
<script language="javascript">
function printspecial(){
document.getElementById("mainContent").focus();
window.print();
}
function print_special()
{
  var disp_setting="toolbar=no,location=no,directories=no,menubar=no,";
      disp_setting+="scrollbars=yes, left=100, top=25";
  var content_vlue = document.getElementById("mainContent").innerHTML;
 
  var docprint=window.open("","",disp_setting);
   docprint.document.open();
   docprint.document.write('<html><head><title>Print</title>');
   docprint.document.write('</head><body onLoad="self.print()"><center>');         
   docprint.document.write(content_vlue);         
   docprint.document.write('</center></body></html>');
   docprint.document.close();
   docprint.focus();
}
</script>
</head>
<body>
<div align="left" id="mainContent">
this is the printing content, this is the printing content,this is the printing content
this is the printing content
this is the printing content
this is the printing content
this is the printing content
this is the printing content
</div>


this is not printing content

<img src="/images/printer.jpg" width="35" height="35" border="0" onClick="printspecial()">
</body>
</html>



but in above case i dont want to open the popup window,
any easy way to print without opening the new window.

Regards
Sanjeevkumar

User avatar
Coditor
New php-forum User
New php-forum User
Posts: 243
Joined: Wed Feb 01, 2006 9:18 am
Location: Netherlands
Contact:

Postby Coditor » Mon Feb 06, 2006 4:59 am

If you create a separate stylesheet for screen and print, you can determine what will printed and what won't.

A simple example:

Code: Select all

<html>
<head>
<style tyle="text/css">
@media screen {
   .donotprint {
      visibility: visible;
   }
   .onlyprint {
      visibility: hidden;
   }
}
@media print {
   .donotprint {
      visibility: hidden;
   }
   .onlyprint {
      visibility: visible;
   }
}
</style>
</head>
<body>
This will be visible online and it will be printed.<br />
<span class="donotprint">This will only be used for online viewing. It will not be printed.<br /></span>
<span class="onlyprint">You won't see this online but it will be printed.<br /></span>
</body>
</html


Coditor

snsanju
New php-forum User
New php-forum User
Posts: 42
Joined: Thu Aug 04, 2005 1:35 am
Location: Bangalore, India
Contact:

Postby snsanju » Tue Feb 07, 2006 12:46 am

hi coditor,
it still printing all other contents, that i dont want.
as you suggest i used the printcontent, but i can give the id's to the other blocks, this is my problem.

i tested ur code, while displaying it donts show the block that we want to print. thats another big problem.

Thanks


Return to “JavaScript”

Who is online

Users browsing this forum: No registered users and 1 guest

cron