Solved

Invoking Print Preview of iFrame contents, not the whole frameset

Posted on 2007-11-13
5
3,323 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
Comment Utility
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
Comment Utility
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
Comment Utility
<$.02>
As with anything to do with programming, sense arises from necessity ;-)
</$.02>
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
Comment Utility
PAQed with points refunded (500)

Computer101
Community Support Moderator
1

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

762 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

10 Experts available now in Live!

Get 1:1 Help Now