Solved

Invoking Print Preview of iFrame contents, not the whole frameset

Posted on 2007-11-13
5
3,384 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article discusses how to implement server side field validation and display customized error messages to the client.
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…

695 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