Avatar of hrhs
hrhs
Flag for United States of America asked on

Printing IFrames for Beginners (Updated)

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
JavaScript.NET Programming

Avatar of undefined
Last Comment
COBOLdinosaur

8/22/2022 - Mon
COBOLdinosaur

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&
hrhs

ASKER
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.
COBOLdinosaur

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&
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
hrhs

ASKER
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.
ASKER CERTIFIED SOLUTION
COBOLdinosaur

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question