Solved

Cross compatible print window button

Posted on 2003-11-30
15
894 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

832 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