Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Print RTF File using JS.

Posted on 2001-07-10
5
Medium Priority
?
614 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
  • 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
This article discusses how to implement server side field validation and display customized error messages to the client.
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…
Suggested Courses

916 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