Solved

Cross compatible print window button

Posted on 2003-11-30
15
899 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

705 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