944,098 Members | Top Members by Rank

Ad:
Aug 20th, 2007
0

How do you print part of a page in Javascript?

Expand Post »
We are offering a coupon for a free soft drink to everyone who fills out our survey. When the user hits the Submit button at the end of the survey, a page appears with the coupon and a Print button. Currently, the whole page prints, including headings and links. I would like to print only the coupon. This is made trickier by the fact that the coupon is customized for each person with the person's name and the date. All help will be greatly appreciated.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
amjones is offline Offline
1 posts
since Aug 2007
Aug 21st, 2007
0

Re: How do you print part of a page in Javascript?

Don't provide the print option on the coupon page. Instead create a 'print view' button at the bottom which will take the user to a page without any frills with just the coupon. I don't know what kind of technique or server side language you are using to persist the user information, but with a bit of hacking, you should be able to easily manage it.
Super Moderator
Featured Poster
Reputation Points: 3241
Solved Threads: 719
Failure as a human
~s.o.s~ is offline Offline
8,873 posts
since Jun 2006
Aug 23rd, 2007
0

Re: How do you print part of a page in Javascript?

You can't control functions which belong to the owner of the computer that is viewing your page.
Reputation Points: 730
Solved Threads: 181
Nearly a Senior Poster
MidiMagic is offline Offline
3,314 posts
since Jan 2007
Aug 24th, 2007
0

Re: How do you print part of a page in Javascript?

> You can't control functions which belong to the owner of the
> computer that is viewing your page.
I don't think this is a question of 'controlling the functions of the owner', its rather a question which deals with the selective content which has to be served to the customer, so that the print function prints only the relevant part of the page.
Super Moderator
Featured Poster
Reputation Points: 3241
Solved Threads: 719
Failure as a human
~s.o.s~ is offline Offline
8,873 posts
since Jun 2006
Aug 25th, 2007
0

Re: How do you print part of a page in Javascript?

What I was thinking is that he wanted to do the equivalent of "print selection" with his code making the selection and choosing the "print selection" option in the Print menu.

That belongs to the user.
Reputation Points: 730
Solved Threads: 181
Nearly a Senior Poster
MidiMagic is offline Offline
3,314 posts
since Jan 2007
Aug 30th, 2007
0

Re: How do you print part of a page in Javascript?

I just checked out three coupon pages provided by well-known companies. All of them print the print button on the paper next to the coupon.
Reputation Points: 730
Solved Threads: 181
Nearly a Senior Poster
MidiMagic is offline Offline
3,314 posts
since Jan 2007
Sep 4th, 2007
0

Re: How do you print part of a page in Javascript?

No problem at all, just have the browser open a new page (upon clicking print)

window.open("your page here")
pass the parameters that you need..
i,e. the coupon is customized for each person with the person's name and the date

window.open("yourPage.htm?customername=xxx&date=yyy")

After the page renders with the coupon,
call
document.print() in yourPage.htm
and maybe close the window after the page prints. and voila, one happy customer
Reputation Points: 10
Solved Threads: 0
Newbie Poster
plasmafire is offline Offline
16 posts
since Oct 2004
Sep 4th, 2007
0

Re: How do you print part of a page in Javascript?

Better solution: use CSS. With CSS you can create a stylesheet dedicated to printing which is separate from the regular page display. This way you can use CSS to remove the parts of the page you don't want printed and even reformat the parts you do want printed. All major browser support this and it is not turned off as JavaScript often is.
Moderator
Reputation Points: 161
Solved Threads: 38
He's No Good To Me Dead
stymiee is offline Offline
1,422 posts
since May 2006
Jul 1st, 2010
0
Re: How do you print part of a page in Javascript?
As stymiee said... CSS is the best option... example

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. @media print{
  2. #div_not_to_print{
  3. display:none;
  4. }
  5.  
  6. #div_to_print{
  7. display:inline-block;
  8. }
  9. }

If every element in your HTML has id or class declare not to print the desired id or class, so when they print the page only print the desire area only, even if JavaScript is turned off. It works with all the browser I used like IE, Safari, Firefox, Chrome, Opera and any Geiko Browser like Firefox.
Reputation Points: 13
Solved Threads: 4
Light Poster
raphie is offline Offline
44 posts
since Jun 2009
Jul 1st, 2010
0
Re: How do you print part of a page in Javascript?
Unfortunately your comment comes almost three years too late for the participants in this thread.
fxm
Reputation Points: 40
Solved Threads: 74
Posting Pro
fxm is offline Offline
591 posts
since Apr 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: PDF Reporting Help
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: CSS Accordion Menu - Javascript help needed





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC