Cross compatible print window button

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
chickcAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ZontarCommented:
<input type="button" value="Print" onclick="if(window.print)window.print();">

This is as cross-browser/platform-agnostic as it gets.
0
chickcAuthor Commented:
Sorry Zontar. Doesn't work on a Mac IE 5.5. Thanks for trying.
0
devicCommented:
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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

chickcAuthor Commented:
Ooops. Mac IE 5.1 that is. :)
0
chickcAuthor Commented:
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
devicCommented:
0
chickcAuthor Commented:
devic: Where is the print button?

This?:  <script>printPageLink();</script>
0
ZontarCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
devicCommented:
<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
chickcAuthor Commented:
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
devicCommented:
>>>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
devicCommented:
>>>I guess this was a harder question than I originally thought.

better:

I guess this was a possible.
0
chickcAuthor Commented:
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
ZontarCommented:
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
chickcAuthor Commented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.