Cross-Origin Policy blocking embedded Google Drive documents

I’ve been embedding PDF files from Google Drive using iframes on my website for several months without issues. However, I started getting browser console errors recently that prevent the documents from displaying properly.

My site is built with ASP.NET MVC and I’m using multiple iframe elements like this:

<iframe src="https://drive.google.com/MyDocumentURL" border="0"></iframe>

The browser shows this error message: “Refused to display https://drive.google.com/MyDocumentURL in a frame because it set ‘X-Frame-Options’ to ‘SAMEORIGIN’.”

What alternatives do I have to work around this cross-origin restriction? The PDFs need to be accessible for users to download from my application.

had the same thing happen to me few days ago. try googles pdf viewer insted: https://docs.google.com/gview?url=YOUR_PDF_URL&embedded=true. it’s a little slow but does the job!

Google changed their X-Frame-Options policy recently - that’s what’s causing your issue. I ran into the same thing a few months ago when my client’s document portal stopped working. The fix that worked for me was switching to Google Drive’s embed URL instead of the regular sharing link. Replace your current URL with https://drive.google.com/file/d/[FILE_ID]/preview - just grab the FILE_ID from your original link. This embed format works with iframes and gets around the X-Frame-Options restrictions. Make sure your Google Drive docs are set to ‘Anyone with the link can view’ or the embed won’t work for your visitors. I’ve been using this method for months now with zero issues.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.