Enjoy unlimited access to all forum features for FREE! Optional upgrade available for extra perks.
Domain summit 2024

Simple (?) JavaScript Question

Status
Not open for further replies.

Bob

Jedi Master
Joined
Apr 8, 2002
Messages
3,102
Reaction score
29
Feedback: 116 / 1 / 0
I want to print out a webpage via the window.print() command.

According to my documentation, window.print() acts exactly as if the user had clicked the "print" button. However, when the command is invoked, the print dialog box ALWAYS pops up.

When I click the little printer at the top of the IE browser, the page just goes to the printer. When I click "File->Print" I always get the print dialog box.

Is there a way to print the webpage without having the print dialog box come up and forcing the user to actually click "OK" or "Cancel" (i.e. simulate the little print icon at the top of the IE browser)?


-Bob
 

Nameable

DNF Member
Legacy Exclusive Member
Joined
Jan 26, 2004
Messages
462
Reaction score
0
Feedback: 5 / 0 / 0
Unfortunately the answer is no.

Javascript doesn't provide a method for "print immediately" -- this would have to be pretty browser specific, as many browsers don't even have a "print immediately" functionality.

We looked into making an activex control to do it, but the client didn't want to pay for that. Post here if you find a free one!
 

Bob

Jedi Master
Joined
Apr 8, 2002
Messages
3,102
Reaction score
29
Feedback: 116 / 1 / 0
I figured out that I cannot do that after I posted my message. UGH. It makes sense though. How would you like to go to a website and haveyour printer start printing a complete unedited version of "War and Peace"? :)

My solution was to put everything I want to print on the browser screen and then issue the window.print() command after that. That eliminated the client from having to click the "Print" button in the print dialog box 800 times and only forces them to do it only once.

I also had the problem of making the output come out on nice pages and not having it all crammed together (i.e. the second page starts half way down the first page). Since HTML does not have a page-break tag, I was able to solve that problem by using a style. (style="page-break-after: always")

Coding - always an interesting job.

-Bob
 

WebCat

Level 7
Legacy Exclusive Member
Joined
Mar 9, 2003
Messages
913
Reaction score
0
Feedback: 0 / 0 / 0
Bob, now I understand why you have so much patience! :)

WebCat
/\_/\
(0 0) php! Perl! Apache! javascript! Linux! CSS! .......AHRRGGGG!
>^<
\__/
 

Anthony Ng

@Nameslave
Legacy Exclusive Member
Joined
May 22, 2002
Messages
4,567
Reaction score
14
Feedback: 16 / 0 / 0

Nameable

DNF Member
Legacy Exclusive Member
Joined
Jan 26, 2004
Messages
462
Reaction score
0
Feedback: 5 / 0 / 0
WOW! Thanks nameslave.

FYI- it's an IE-only solution, but a solution nonetheless. Hopefully bad people don't get a hold of this, or we could be killing an exceptional number of trees.
 
Status
Not open for further replies.

The Rule #1

Do not insult any other member. Be polite and do business. Thank you!

Sedo - it.com Premiums

IT.com

Premium Members

AucDom
UKBackorder
Be a Squirrel
MariaBuy

Our Mods' Businesses

UrlPick.com
URL Shortener

*the exceptional businesses of our esteemed moderators

Top Bottom