Solved

Invoking Print Preview of iFrame contents, not the whole frameset

Posted on 2007-11-13
5
3,339 Views
Last Modified: 2013-11-07
Ok, in the following code it invokes print preview.  The .aspx page I'm working with is a page that contains 4 different iframes.  I would like to do print preview of just the contents in iFrame #4, but when this code is executed it's giving a print preview of the main page that contains the 4 iframes.  That's the problem.  

I've tried lots of stuff, but I can't figure it out.

Here is the code of the page in iframe #4 that calls the javascript method to open print preview on page load:

    <script language="javascript" type="text/javascript">
        function printpr()
        {
            var OLECMDID = 7;
            /* OLECMDID values:
            * 6 - print
            * 7 - print preview
            * 1 - open window
            * 4 - Save As
            */
            var PROMPT = 2; // 2 DONTPROMPTUSER
            var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0  CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
            top.frames.printFrame.document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
            top.frames.printFrame.WebBrowser1.ExecWB(OLECMDID, PROMPT);
            top.frames.printFrame.WebBrowser1.outerHTML = "";
        }    
    </script>

the code after the WebBrowser declaration says "top.frames.printFrame".  I added that there to try and specify that I only wanted to embed the browser object in the iframe named "printFrame" (iframe #4), but it doesn't do anything differently.  It could be the same thing without that, obviously.

Help is much appreciated.
0
Comment
Question by:Gewgala
5 Comments
 
LVL 22

Expert Comment

by:RedKelvin
ID: 20416710
Hi,
You have probably seen this, but I don't think it is possible

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2409699&SiteID=1

RedK
0
 
LVL 7

Author Comment

by:Gewgala
ID: 20428451
lol, in that link you provided, that's a link to a post that I made in the microsoft forums.  :)  I thought that looked familiar!  I hadn't read the reply though.  I'll check out the link that was provided.

By the way, I was able to get it to work where you only print the preview of the selected iframe.  Here was my workaround:

a print.css file
and javascript

In my print.css file, I pretty much made everything invisible to the printer/print preview by giving display:none properties to everything basically, except one literal control.  With javascript, I used innerHTML to take the contents of the iframe and then put them in the literal control that was the only thing visible to the printer, thanks to the print.css file that I referenced.  This gave me exactly what I wanted.  So in short, it wasn't previewing the contents of the iframe necessarily, although it was indirectly, rather it was copying the contents of the iframe to a literal control on the main page and making everything but the literal control invisible with my custom print.css file.

Does that make sense?
0
 
LVL 29

Expert Comment

by:Badotz
ID: 20428580
<$.02>
As with anything to do with programming, sense arises from necessity ;-)
</$.02>
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 20943278
PAQed with points refunded (500)

Computer101
Community Support Moderator
1

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

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

914 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

18 Experts available now in Live!

Get 1:1 Help Now