Solved

Cross compatible print window button

Posted on 2003-11-30
15
892 Views
Last Modified: 2008-02-01
Need a cross browser/OS compatible, javascript "print window" button. If it doesn't work with macintosh, don't bother posting a reply. Thanks, Chick
0
Comment
Question by:chickc
  • 7
  • 5
  • 3
15 Comments
 
LVL 11

Expert Comment

by:Zontar
ID: 9845436
<input type="button" value="Print" onclick="if(window.print)window.print();">

This is as cross-browser/platform-agnostic as it gets.
0
 

Author Comment

by:chickc
ID: 9845580
Sorry Zontar. Doesn't work on a Mac IE 5.5. Thanks for trying.
0
 
LVL 25

Assisted Solution

by:devic
devic earned 250 total points
ID: 9845687
right chickc, mac is bad system ;)

did you release Mac IE 5.5 self?
i know only about 5.2* version.

anyway Zontar answer is correct, once more you can avoid to view button for "Non printable" browsers;
===================================
<script>

function printPageLink()
{
      if(window.print)
      {
            document.write("<a href=javascript:window.print()>print this page</a>")
      }

      else
      {
            //Sorry, this function is not supported on your browser.
            document.write(" To print this page, please select Print from your file menu.")
      }

}
printPageLink();
</script>
0
 

Author Comment

by:chickc
ID: 9845688
Ooops. Mac IE 5.1 that is. :)
0
 

Author Comment

by:chickc
ID: 9845704
devic: Have I placed into the page correctly?
http://www.mediabuys.us/activity-estimate-request.html

Because it doesn't appear to be working.

Chick
0
 
LVL 25

Expert Comment

by:devic
ID: 9845737
0
 

Author Comment

by:chickc
ID: 9845755
devic: Where is the print button?

This?:  <script>printPageLink();</script>
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 11

Accepted Solution

by:
Zontar earned 250 total points
ID: 9845760
WFM, MSIE 5.0/MSIE 6.0/Mozilla 1.5/Opera 7.21 on Windows.

If the browser doesn't support the window.print() method, there's nop other way to to do it. (Well, you can use an ActiveWrecks control for MSIE, but that's not going to work on a Mac, either.)

I wouldn't even bother with a function, since the script get executed only once:

<script type="text/javascript">
output = "Use your browser's Print button to print this page.";

if(window.print)
  output = "<input type=\"button\" value=\"Print\" onclick=\"window.print();\"";

document.writeln(output);
</script>

but otherwise devic's defencive scripting is the best that you can do here -- provide the print button for browsers that have the capability to use it, and don't bother showing it to browsers that don't.
0
 
LVL 25

Expert Comment

by:devic
ID: 9845765
<script>printPageLink();</script>

here i call the function printPageLink();


in the function printPageLink() i look if the browser can execute window.print.

if yes
will be print button with value "Print"

else only text :
To print this page, please select Print from your file menu.
0
 

Author Comment

by:chickc
ID: 9845785
But then that must mean that if the user is using a Mac browser, they cannot print the window by clicking a button on the page. If that is the case with your code, it is not what I'm looking for.

I guess this was a harder question than I originally thought.

Dig deeper! I need this button, gang!  :)
0
 
LVL 25

Expert Comment

by:devic
ID: 9845811
>>>that must mean that if the user is using a Mac browser, they cannot print the window by clicking a button on the page

you are right, if is impossible then is impossible.

you can insert anyway button if you want.
http://home.arcor.de/athens/expexc/js/print/chickc.html

if you want to have possibility to print on mac, then i think you need really release IE 5.5 ;)
0
 
LVL 25

Expert Comment

by:devic
ID: 9845818
>>>I guess this was a harder question than I originally thought.

better:

I guess this was a possible.
0
 

Author Comment

by:chickc
ID: 9845826
devic: Very funny. I'll see if I can help Microsoft with a new release...just for the sake of this button. Seriously though, I could swear I've seen this button somewhere before, so the code must exist. Any other way to do it? Perhaps a cgi script?
0
 
LVL 11

Expert Comment

by:Zontar
ID: 9845910
Perhaps you were using a non-Microsoft browser?

Seriously, if the browser doesn't support window.print(), then there's no way to do it, anymore than you can glue a propellor on a tree and expect it to fly. The capability simply is not there.

> Perhaps a cgi script?

This is what prompted the propellor remark. Only now you're proposing to glue it onto the tree in hopes this will enable the tree to swim. CGI has nothing to do with browser capabilities.
0
 

Author Comment

by:chickc
ID: 9845932
I have to admit, you guys are very entertaining. So because you've at least made me smile, I'll split the points between you.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now