wood burning stoves 2.0*
The moose likes HTML, CSS and JavaScript and the fly likes Print Preview using Javascript doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Print Preview using Javascript doubt" Watch "Print Preview using Javascript doubt" New topic
Author

Print Preview using Javascript doubt

Srikkanth Mohanasundaram
Ranch Hand

Joined: Feb 07, 2007
Posts: 185
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

Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
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

Joined: Feb 07, 2007
Posts: 185
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
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Forgot to say, what does your code look like that fails.

What would the link do?



Eric
Srikkanth Mohanasundaram
Ranch Hand

Joined: Feb 07, 2007
Posts: 185
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
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
There is no way to open up the preview with JavaScript

Eric
Srikkanth Mohanasundaram
Ranch Hand

Joined: Feb 07, 2007
Posts: 185
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
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Um, that code is not going to work in 80+% of browsers out there.

Eric
Srikkanth Mohanasundaram
Ranch Hand

Joined: Feb 07, 2007
Posts: 185
Thanks for your help Eric
Srikkanth Mohanasundaram
Ranch Hand

Joined: Feb 07, 2007
Posts: 185
Thanks for your help Eric
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Print Preview using Javascript doubt