Solved

Printing a specific frame on request

Posted on 1999-01-26
5
197 Views
Last Modified: 2013-12-25
I want to put a button/link in an asp page that will print the frame it's in (and only that frame) automatically. ANY suggestions welcome, but if the view is changed (another page loaded, etc), I need to be able to return to the current "view" without knowing what it looks like (I don't know what layout the "higher level" frames takes on).

A possible solution is to place a button which feeds keystrokes to the browser after the frame got focus. The keys would be CTRL-P, ALT-R, <ENTER> or some such. But how does one do that?
0
Comment
Question by:ayrezyle
  • 4
5 Comments
 
LVL 1

Accepted Solution

by:
ptruman earned 100 total points
ID: 1859194
Bung this in your FRAME's HTML source :
<script language="JavaScript">
<!--
function tmt_print() {
    if (document.all) {
        var OLECMDID_PRINT = 6;
        var OLECMDEXECOPT_DONTPROMPTUSER = 2;
        var OLECMDEXECOPT_PROMPTUSER = 1;
        var WebBrowser = "<OBJECT ID=\"WebBrowser1\" WIDTH=0 HEIGHT=0 CLASSID=\"CLSID:8856F961-340A-11D0-A96B-00C04FD705A2\"></OBJECT>";
        document.body.insertAdjacentHTML("beforeEnd", WebBrowser);
        WebBrowser1.ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_PROMPTUSER);
        WebBrowser1.outerHTML = "";
    } else {
        self.print();
    }
}
//-->
</script>

Then in the BODY put an onload, so
<BODY onLoad="tmt_print()">

This WILL bring up the print window, theres NO way around
this....so it's not 100% automatic....but it does
do (unless overridden) the specified frame...

0
 
LVL 1

Author Comment

by:ayrezyle
ID: 1859195
That printed the whole set of frames. Each individually. When I moved the JScript call to an <A href= "JScript:tmt_print"> PRINT </A> tag in the relevant frame, it worked beautifully (printing just the focused frame)! Thanks!
0
 
LVL 1

Author Comment

by:ayrezyle
ID: 1859196
Problem: When I click OK in the popup it prints fine, but when I choose "cancel" it pops up the window _again_ and if I then click cancel again, it gives me a script error! How  do I correct this?
0
 
LVL 1

Author Comment

by:ayrezyle
ID: 1859197
Problem: When I click OK in the popup it prints fine, but when I choose "cancel" it pops up the window _again_ and if I then click cancel again, it gives me a script error! How  do I correct this?
0
 
LVL 1

Author Comment

by:ayrezyle
ID: 1859198
The problem is at the following line of code :
WebBrowser1.ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_PROMPTUSER);
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Learn by example how to specify CSS selectors for Selenium WebDriver test automation software.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now