This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Print Preview using Javascript doubt

 
Srikkanth Mohanasundaram
Ranch Hand
Posts: 240
1
  • 0
  • 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

 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • 0
  • 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: 240
1
  • 0
  • 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
Rancher
Posts: 15385
6
  • 0
  • 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: 240
1
  • 0
  • 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
Rancher
Posts: 15385
6
  • 0
  • 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: 240
1
  • 0
  • 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
Rancher
Posts: 15385
6
  • 0
  • 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: 240
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your help Eric
 
Srikkanth Mohanasundaram
Ranch Hand
Posts: 240
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your help Eric
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic