Google Views in a frame because it set 'X-Fram

2020-06-01 07:49发布

问题:

<iframe src='https://docs.google.com/viewer?url=https://docs.google.com/document/d/125CJmmlBfy7UgfYuBAmb1_HSCuyz8NV133361KTK1SE/export?format%3Dpdf&id=125CJmmlBfy7UgfYuBAmb1_HSCuyz8NV133361KTK1SE&embedded=false'  frameborder='0'></iframe>

after this code I have next error

Refused to display 'https://docs.google.com/a/myrussiaonline.ru/viewer?url=https://docs.google.…ormat%3Dpdf&id=125CJmmlBfy7UgfYuBAmb1_HSCuyz8NV133361KTK1SE&embedded=false' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.

If I set

<iframe src='https://docs.google.com/viewer?url=https://docs.google.com/document/d/125CJmmlBfy7UgfYuBAmb1_HSCuyz8NV133361KTK1SE/export?format%3Dpdf&id=125CJmmlBfy7UgfYuBAmb1_HSCuyz8NV133361KTK1SE&embedded=true'  frameborder='0'></iframe>

Then, all fine

Can I set &embedded=false and have correct render without error?

Thanks

回答1:

The only way I've found to get the Google Docs Viewer to work in an iframe is:

<iframe src="https://docs.google.com/viewer?srcid=[YOUR_FILE'S_ID_HERE]&pid=explorer&efh=false&a=v&chrome=false&embedded=true" width="800" height="600" style="border: none;"></iframe>


回答2:

Try this tutorial-

https://www.youtube.com/embed/A5SkbcId-v0

U should have your answer.

Update-

According to Google Policy, if u like to have your document viewed with a iFrame, then embedded=true should be in the URL.

Demo Code-

<iframe src='https://docs.google.com/viewer?url=https://docs.google.com/document/d/125CJmmlBfy7UgfYuBAmb1_HSCuyz8NV133361KTK1SE/export?format%3Dpdf&id=125CJmmlBfy7UgfYuBAmb1_HSCuyz8NV133361KTK1SE&embedded=true'  frameborder='0'></iframe>



回答3:

First you should go to your document on google drive :

  1. click file
  2. publish to the web
  3. embed
  4. publish

You will get the code of the iframe you can use it to visualize your spreadsheet without the possibility to edit it



回答4:

No, you can not, this parameter is specify that source would be embedded. And the idea behind using it is to avoid clickjacking attacks