Wrox Programmer Forums
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 3rd, 2005, 08:02 AM
Friend of Wrox
 
Join Date: Sep 2004
Posts: 103
Thanks: 0
Thanked 0 Times in 0 Posts
Default print

Is it possible to print the content of a hidden iframe(by assigning display:none as its style)
Calling the window.frame.print results in printing the current page not the iframe.

 
Old July 3rd, 2005, 12:30 PM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Well normally to print a frame you must call the focus method first:
Code:
top.frames["myFrame"].focus()
but I doubt this will work when the style.display is "none".

--

Joe (Microsoft MVP - XML)
 
Old July 4th, 2005, 05:32 AM
Friend of Wrox
 
Join Date: Sep 2004
Posts: 103
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You're right it works fine when the iframe's display style is not 'none'
I tried visibility:hidden and it fails too(prints the container page)
yet...any other solution?


 
Old July 4th, 2005, 07:40 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Change the display before printing and reset to display:none afterwards or use the @media directive (other examples in this forum) to have the display:none in screen mode but not in print mode.

--

Joe (Microsoft MVP - XML)
 
Old July 4th, 2005, 08:29 AM
Friend of Wrox
 
Join Date: Sep 2004
Posts: 103
Thanks: 0
Thanked 0 Times in 0 Posts
Default

What's the problem with this code of mine(where 'toPrint' is the id and name of an iframe):

      function printReceipt(){
        document.getElementById("toPrint").style.display=" ";
        window.toPrint.focus();
        window.toPrint.document.write("x");
        window.toPrint.print();
        document.getElementById("toPrint").style.display=" none";
        return false;
      }
this function prints nothing and without any error!


 
Old July 4th, 2005, 08:47 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

I think you need to close the document, I would also move it around and add a display style:
Code:
document.getElementById("toPrint").style.display="block"; 
window.toPrint.document.write("x"); 
window.toPrint.document.close();
window.toPrint.focus();
//etc.
--

Joe (Microsoft MVP - XML)
 
Old July 4th, 2005, 10:08 AM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

You might also try opacity. Give the iframe 100% opacity (fully transparent), and then layer it underneath the rest of your content, e.g. position: absolute; z-index: -1. In theory, the opacity would apply to the iframe but not to the contents of the iframe, since it is a separate document. You might also try a print style sheet for the main document that has the visibility, display, opacity (whichever works) set to visible, and not visible in the normal style sheet.

In Explorer opacity is set with a proprietary filter property.
http://msdn.microsoft.com/workshop/a...ters/alpha.asp

iframe {
    filter:progid:DXImageTransform.Microsoft.Alpha(opa city=100);
}

In Mozilla, prior to Firefox 1.0 (Netscape 7, Mozilla 1.7, etc), it's the -moz-opacity property, which accepts a decimal value between 0 (fully transparent) and 1 (fully opaque).

For instance:
iframe {
    -moz-opacity: 0;
}

Or

iframe {
    -moz-opacity: 0.1; /* mostly transparent */
}

Firefox 1.0 and later take the CSS3 opacity property (same value). Safari is said to support -khtml-opacity, which is the same as the CSS 3 opacity property, don't know though never tried it.

http://www.w3.org/TR/2003/CR-css3-co.../#transparency

HTH!

Regards,
Rich

--
[http://www.smilingsouls.net]
Mail_IMAP: A PHP/C-Client/PEAR solution for webmail
Author: Beginning CSS: Cascading Style Sheets For Web Design





Similar Threads
Thread Thread Starter Forum Replies Last Post
Textbox problem print preview vs. print jenisageek Access 5 May 2nd, 2008 12:54 PM
print the hidden page without the print dialog box kayzem Classic ASP Basics 0 April 21st, 2005 11:31 PM
Print and print preview file on the website withou appleLover General .NET 0 February 19th, 2005 02:24 AM
Macro to print to different print objects mikericc Access 1 April 21st, 2004 10:57 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.