Printing IFrames for Beginners (Updated)

hrhs
hrhs used Ask the Experts™
on
I know there are a ton of questions here about printing IFrames.  I have gone through most of them and I am not getting them to work.  Many of them are from years ago and I afraid maybe they're outdated?

I am embedding a Google Doc (so cross-domain might be an issue) in a page and I am trying to find a cross browser solution that works to print the content of the IFrame.  I am somewhat new to javascript so I would need some help with the complete function syntax and the syntax for the html to call the function.  I've tried all kinds of things, nothing seems to work.  My IFrame id is "policy".

Thanks,

Dave
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2013

Commented:
Cross-domain is the issue.  Modern browsers do not permit it because it was a huge security hole in the past that resulted in tens of thousands of sites hacked and millions of users infected with virus code.

You will not find a way to print the contents of the iframe from a main page no matter what you try.  It will always fail as a security violation.  Either the page in the frame must contain print functionality, or you can bring the page in without the frame and print using the browser or print screen.

Cd&

Author

Commented:
Would you know a print solution for embedded Google Docs?

I am attempting to formulate a solution for embedding hundreds of policy documents on an Intranet and I would have to have a print solution for posting the policies in paper form within department physical locations.
Top Expert 2013

Commented:
Well if you are doing it for an intranet app.  Just save the complete pages on your server.  Then you can serve them from the same local domain and there is no longer any cross-domain issue.  

Or scrape the pages and save the text components in a database.  then you can generate the pages as needed for both viewing and printing.

Cd&

Author

Commented:
Well, the reason I want to keep them in Google Docs is to empower the document creators and collaborators to maintain their own documents as a team.
Top Expert 2013
Commented:
Why not just pop the page out of the iframe.  Just open the document in a regular window and use the browser to print.

A button in the main page like:
<button name="setup" onclick="top.location.href=document.getElementById('policy').src;">click to open full page</button>

Open in new window


Then after printing, the back button returns them to the page with the iframe.

Cd&

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial