| | |
How do you print part of a page in Javascript?
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Aug 2007
Posts: 1
Reputation:
Solved Threads: 0
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.
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.
I don't accept change; I don't deserve to live.
> 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.
> 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.
I don't accept change; I don't deserve to live.
•
•
Join Date: Oct 2004
Posts: 16
Reputation:
Solved Threads: 0
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
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
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.
John Conde
Brainyminds | Merchant Account Services | I Love Code
IT'S HERE: Merchant Accounts 101 Everything you need to know about merchant accounts!
Brainyminds | Merchant Account Services | I Love Code
IT'S HERE: Merchant Accounts 101 Everything you need to know about merchant accounts!
![]() |
Similar Threads
- Print control to print the Content Page from a Master Page (ASP.NET)
- print web page (JavaScript / DHTML / AJAX)
- How would I display somethign only if javascript is enabled? (JavaScript / DHTML / AJAX)
- php + mysql (PHP)
- Print HTML page / download updates (VB.NET)
- How do i print asp page on client side "only the contents" (ASP)
- how can i use php to print a specified part of a web page? (PHP)
- IN Nero cover designer when I click print ican I get a page without a print command. (Windows Software)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Delay Window Close
- Next Thread: Javascript Function return value into PHP or not ?? Please help !!
| Thread Tools | Search this Thread |
acid2 ajax ajaxcode ajaxexample ajaxhelp ajaxjspservlets animate array automatically beta box browser bug calendar captchaformproblem cart close codes column cookies css date debugger decimal dependent design disablefirebug dom download element embed engine enter error events ext file firefox focus form frameworks getselection google gwt gxt hiddenvalue highlightedword hint html htmlform ie7 iframe index java javascript javascripthelp2020 jawascriptruntimeerror jquery jsp libcurl listbox maps masterpage media menu microsoft mimic mp4 onmouseoutdivproblem onmouseover paypal pdf php player position post problem programming prototype redirect regex safari scale scriptlets scroll search security select software sql text textarea toggle unicode variables w3c website window windowofwords windowsxp






