Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Print RTF File using JS.

Posted on 2001-07-10
5
Medium Priority
?
598 Views
Last Modified: 2010-08-05
Hi guys,

How can I print a RTF file (Word) using JavaScript.

I have a RTF file open in a Frame in a FrameSet, and now want to print that RTF file as soon as the user clicks on a Button on another Frame.

I have 70 points available, but if someone wants more points, I'll arrange it !!

Thank you very much.

Pieter
0
Comment
Question by:PieterJ
[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
  • 2
  • 2
5 Comments
 
LVL 1

Accepted Solution

by:
bowker earned 280 total points
ID: 6269909
Pieter --

Here's cross-browser JS code that will print the contents of "document" ... so change the reference to what gets printed, then call this when the person clicks on the button:

<script language="JavaScript">
<!--

     var da = (document.all) ? 1 : 0;
     var pr = (window.print) ? 1 : 0;
     var mac = (navigator.userAgent.indexOf("Mac") != -1);

     function printPage() {
            if (pr) // NS4, IE5
              window.print()
            else if (da && !mac) // IE4 (Windows)
              vbPrintPage()
            else // other browsers
              alert("Sorry, your browser doesn't support this feature.");
            return false;
     }

     if (da && !pr && !mac) with (document) {
       writeln('<OBJECT ID="WB" WIDTH="0" HEIGHT="0" CLASSID="clsid:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>');
       writeln('<' + 'SCRIPT LANGUAGE="VBScript">');
       writeln('Sub window_onunload');
       writeln('  On Error Resume Next');
       writeln('  Set WB = nothing');
       writeln('End Sub');
       writeln('Sub vbPrintPage');
       writeln('  OLECMDID_PRINT = 6');
       writeln('  OLECMDEXECOPT_DONTPROMPTUSER = 2');
       writeln('  OLECMDEXECOPT_PROMPTUSER = 1');
       writeln('  On Error Resume Next');
       writeln('  WB.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER');
       writeln('End Sub');
       writeln('<' + '/SCRIPT>');
     }

// -->
</script>

Good luck!

Bob.
0
 
LVL 19

Expert Comment

by:webwoman
ID: 6270299
Just to make it clear -- it only works for sure in IE, on a PC. It may not work properly if they're using Netscape, and it won't work if they use anything else.
0
 
LVL 1

Expert Comment

by:bowker
ID: 6270450
AFAIK, it works for NS and IE on a PC, UNIX, LINUX, etc. - Mac versions of both browsers have problems, which is why Macs are specifically excluded.  Do you know of an NS version that this won't work on ...?
0
 
LVL 19

Expert Comment

by:webwoman
ID: 6271604
This is a FRAMED page -- so it gets a little tougher.

Also... if you're using Netscape, the file won't open anyway, you'll get prompted to download it. So printing from the browser is a moot point. ;-)
0
 

Author Comment

by:PieterJ
ID: 6272152
Thanks to both of you, I see it works if the print button and the rtf document is in the same frame, but my problem is the fact that the RTF file is in another frame from where the print button is. So as soon as the RTF file opened up in the other frame, I loose control over that frame and Word has the control now. So if you use something like window.parent.docframe.print() it says that it can not find docframe.

Thanks!
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.

Question has a verified solution.

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

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
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…

688 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