Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print "Only the Selected Frame" 1

Status
Not open for further replies.

sheong

Programmer
Dec 7, 2003
17
SG
Hi,
i trying to use print preview in my asp page contain 3 frames. I using the following function, I able to do the print preview. But it is always default to "As laid out on Screen".
How can i modify the following function so that it can set it to "Only the Selected Frame" ? Or any reference about Print Preview on selected frame ?

Thank you!

function printpr(OLECMDID)
{
//var OLECMDID = 10;
/* OLECMDID values:
* 6 - print
* 7 - print preview
* 8 - page setup (for printing)
* 1 - open window
* 4 - Save As
* 10 - properties
*/
var PROMPT = 1; // 1 PROMPT & 2 DONT PROMPT USER
var WebBrowser = '<OBJECT ID=&quot;WebBrowser1&quot; WIDTH=0 HEIGHT=0 CLASSID=&quot;CLSID:8856F961-340A-11D0-A96B-00C04FD705A2&quot;></OBJECT>';
document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
WebBrowser1.ExecWB(OLECMDID,PROMPT);
WebBrowser1.outerHTML = &quot;&quot;;

}
 
how would you select the frame...would it be a select box or would it be the frame that your gonna the above function in?
jammer1221
 
Yup, is a frame that contain the above function.
Then i trying to click on a button, it will call the printpr function.

do you get what i meant ?
 
sheong,

I've neot tried it, but using JavaScript, it might be possble to focus a frame - something like
Code:
frameName.focus();
.

As I said, I haven't tried it, but if you click in a frame and print, IE certainly gives you the contents of that frame, so maybe the focus method will yield the same results?

Hope this helps!

Dan
 
Dan,

thankx for ur reply. I had tried, but still give me the same result. May be you can copy the above function into a frame and try from it.

Appreciate if you can help me.
 
here's what they had at IRT.org for the question:
How do I know which frame has the focus?

You can't, unless you maintain a variable in the parent frame, that you update when any onFocus or onBlur event handler within each of the frames body tags are triggered.

 
I found this on MSDN:

&quot;WebBrowser prints the frame that has the focus by default; we just need to set the focus to the required frame (or to the window itself). This is required for Internet Explorer 4.x only. With Internet Explorer 5, we just call frame.print() on a specific frame.&quot;

So if you're running IE5, not an issue. For IE4, the solution may or may not work, depending on the exact version of IE4:

&quot;Internet Explorer 4.0: Unfortunately there is no way in Internet Explorer 4.0 to set the focus on to a specific frame because frame.focus() simply has no effect. This is fixed with Internet Explorer 4.01, but users of Internet Explorer 4.0 will be able to print only the frame/window that has a focus.&quot;

&quot;Internet Explorer 4.01: If we use frame.focus() followed by WebBrowser1.ExecWB, WebBrowser doesn't take the focus change immediately and ends up printing the whole window. We can work around this with a setTimeout() call to retain the ExecWB command (technically, until the next message loop pump).&quot;

&quot;Internet Explorer 4.x: Some unpleasant issues can also arise when we call printFrame from inside a frame. If the user cancels, the printing dialog will &quot;bubble&quot; for each frame nesting level up to the top window. This behavior is undesirable, but help is at hand. If you really need such functionality, you can use the Scripting Factory ActiveX control.&quot;

The full URL to this article is at:
Hope this helps!

Dan
 
Hello Dan,

thankx for ur reply.

I know that I can use the following function to initiate a &quot;Print Preview&quot; function in IE6, but is it posible to use the same function on the frameset. In other words when this function is used on the pages with frames it shows the whole frameset.

Is it possible to &quot;Print Preview&quot; just on page of the frameset and not the whole thing? Here is the function:

Code:
function printpr() { 
var OLECMDID = 7; /* OLECMDID values: 
* 6 - print 
* 7 - print preview 
* 1 - open window 
* 4 - Save As */ 

var PROMPT = 1; // 2 DONTPROMPTUSER var WebBrowser= '<OBJECT ID=&quot;WebBrowser1&quot; WIDTH=0 HEIGHT=0 CLASSID=&quot;CLSID:8856F961-340A-11D0-A96B-00C04FD705A2&quot;></OBJECT>'; 

document.body.insertAdjacentHTML('beforeEnd', WebBrowser); WebBrowser1.ExecWB(OLECMDID, PROMPT);
 WebBrowser1.outerHTML = &quot;&quot;; }
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top