Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Print Preview using Javascript doubt

 
Ranch Hand
Posts: 243
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,

In our application ,we have a lot of detail pages (you can think of article details) all of which will contain a link at the bottom named "Print Preview" which opens a new window showing the detail alone (stripping out the Header,footer, left navigation and other stuff) and the user can print the detail from this window.
To facilitate this, what i tried was to open a new window , and using javascript i got the detail section HTML (from the parent) and wrote the same onto the child window(using innerHTML).Obviously this worked,but when the I see the page using print preview it shows a blank page. I guess this is because the "browser print" tries to print the HTML source and not the changes done on the DOM later.So i had to resort to a server call to get the detail again and fix this.
Though I don't have issues anymore, i still feel bad about calling the server when what i need is so close.I tried this with IE, didn't get to try with Firefox but i suspect it will work the same way.
Any better ways of doing this?

Thanks,
Srikkanth

 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about you skip the new window thing and make a stylesheet that does all fo the work for you. It can be accoplished with CSS Print Media.

Here is a nice article on doing this: http://www.alistapart.com/articles/goingtoprint/

Eric
 
Srikkanth Mohanasundaram
Ranch Hand
Posts: 243
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Eric,
Thanks for the link. What should the "Print Preview" anchor refer to? Oh do you mean when the user tries to print the detail page ,the browser will use the print CSS?

Thanks,
Srikkanth
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Forgot to say, what does your code look like that fails.

What would the link do?



Eric
 
Srikkanth Mohanasundaram
Ranch Hand
Posts: 243
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Eric ,
This opens the Print Dialog of the browser, is there anyway to open the Print Preview dialog ?
My code doesn't fail in fact i'm going back to the server to get the details on the Print Preview dialog. Now I added the Print css and it looks good.But I think the users would need a Preview.

Thanks for your help.
Srikkanth
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no way to open up the preview with JavaScript

Eric
 
Srikkanth Mohanasundaram
Ranch Hand
Posts: 243
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay Thanks for your help Eric.
This is a requirement (to open a preview window) , so I guess I would have to go back to the new window thing and hit the server.

I found this on the net,couldn't understand much though




Thanks,
Srikkanth
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Um, that code is not going to work in 80+% of browsers out there.

Eric
 
Srikkanth Mohanasundaram
Ranch Hand
Posts: 243
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your help Eric
 
Srikkanth Mohanasundaram
Ranch Hand
Posts: 243
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your help Eric
 
The knights of nee want a shrubbery. And a tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic