Solved

Invoking Print Preview of iFrame contents, not the whole frameset

Posted on 2007-11-13
5
3,369 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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

730 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