• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 905
  • Last Modified:

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
0
chickc
Asked:
chickc
  • 7
  • 5
  • 3
2 Solutions
 
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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
 
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 7
  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now