Add-In: Embedding SharePoint content in iframe (xls, PDF)

%3CLINGO-SUB%20id%3D%22lingo-sub-213679%22%20slang%3D%22en-US%22%3EAdd-In%3A%20Embedding%20SharePoint%20content%20in%20iframe%20(xls%2C%20PDF)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-213679%22%20slang%3D%22en-US%22%3E%3CP%3E%3CI%3EWe%20try%20to%20embed%20SharePoint%20content%20in%20an%20iFrame.%20Therefore%20we%20use%20the%20GUID%20of%20the%20doc%20to%20build%20the%20ifram%20URL.%3C%2FI%3E%3C%2FP%3E%3CDIV%20class%3D%22code%20panel%22%3E%3CDIV%20class%3D%22codeContent%20panelContent%22%3E%3CPRE%3E(%5B%5BHOST%5D%E2%80%8C%5D_layouts%2F15%2FWopiFrame.aspx%3Fsourcedoc%3D%7B%5B%5BGUID%5D%5D%7D%26amp%3Baction%3Dembedview%26amp%3BwdStartOn%3D1)%3C%2FPRE%3E%3C%2FDIV%3E%3C%2FDIV%3E%3CP%3ETested%20with%203%20different%20files.%3C%2FP%3E%3CHR%20%2F%3E%3COL%3E%3CLI%3E%3CSTRONG%3E.pptx%3C%2FSTRONG%3E%3C%2FLI%3E%3C%2FOL%3E%3CP%3EWorking%20fine.%3CBR%20%2F%3EIframe-URL%20is%3C%2FP%3E%3CDIV%20class%3D%22code%20panel%22%3E%3CDIV%20class%3D%22codeContent%20panelContent%22%3E%3CPRE%3Ehttps%3A%3CSPAN%20class%3D%22code-comment%22%3E%2F%2F..._layouts%2F15%2FWopiFrame.aspx%3Fsourcedoc%3D%7Bcfca68b9-c498-4c9b-a790-52d0f522b684%7D%26amp%3Baction%3Dembedview%26amp%3BwdStartOn%3D1%3C%2FSPAN%3E%3C%2FPRE%3E%3C%2FDIV%3E%3C%2FDIV%3E%3CP%3EEverything%20is%20working%20fine.%20Preview%20is%20available.%3C%2FP%3E%3CHR%20%2F%3E%3COL%3E%3CLI%3E%3CSTRONG%3E.xls%3C%2FSTRONG%3E%3C%2FLI%3E%3C%2FOL%3E%3CP%3EIframe%20gets%20blocked.%3CBR%20%2F%3EIframe-URL%20is%3C%2FP%3E%3CDIV%20class%3D%22code%20panel%22%3E%3CDIV%20class%3D%22codeContent%20panelContent%22%3E%3CPRE%3Ehttps%3A%3CSPAN%20class%3D%22code-comment%22%3E%2F%2F..._layouts%2F15%2FWopiFrame.aspx%3Fsourcedoc%3D%7B51bf3f39-addc-48aa-b9a0-7bd1b56d9f07%7D%26amp%3Baction%3Dembedview%26amp%3BwdStartOn%3D1%3C%2FSPAN%3E%3C%2FPRE%3E%3C%2FDIV%3E%3C%2FDIV%3E%3CP%3EBrowser%20shows%20the%20following%20message%3A%3C%2FP%3E%3CDIV%20class%3D%22code%20panel%22%3E%3CDIV%20class%3D%22codeContent%20panelContent%22%3E%3CPRE%3ERefused%20to%20display%20%3CSPAN%20class%3D%22code-quote%22%3E'https%3A%3CSPAN%20class%3D%22code-comment%22%3E%2F%2F..._layouts%2F15%2FWopiFrame.aspx%3Fsourcedoc%3D%7B51bf3f39-addc-48aa-b9a0-7bd1b56d9f07%7D%26amp%3Baction%3Dembedview%26amp%3BwdStartOn%3D1'%3C%2FSPAN%3E%20in%20a%20frame%20because%20it%20set%20'X-Frame-Options'%20to%20'sameorigin'.%3C%2FSPAN%3E%3C%2FPRE%3E%3C%2FDIV%3E%3C%2FDIV%3E%3CP%3EIts%20exactly%20the%20same%20URL%20as%20before%2C%20just%20the%20query%20parameters%20are%20different%20(different%20GUIDs).%3CBR%20%2F%3EWhen%20URLs%20get%20opened%20directly%20in%20the%20browser%2C%20you%20can%20see%20a%20small%20redirect.%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CBR%20%2F%3EThe%20PPTX%20gets%20redirected%20to%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fxyz.sharepoint.com%E2%80%8C%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fxyz.sharepoint.com%E2%80%8C%3C%2FA%3E%3CSTRONG%3E%2F%3Ap%2Fr%2F%3C%2FSTRONG%3E%E2%80%8Csites%2F...%2F_layouts%2F15%2FWopiFrame.aspx%3F....%3CBR%20%2F%3EThe%20XLS%20gets%20redirected%20to%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fxyz.sharepoint.com%E2%80%8C%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fxyz.sharepoint.com%E2%80%8C%3C%2FA%3E%3CSTRONG%3E%2F%3Ax%2Fr%2F%3C%2FSTRONG%3E%E2%80%8Csites%2F...%2F_layouts%2F15%2FWopiFrame.aspx%3F....%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3EQUESTION%3A%20Why%20does%20it%20get%20handled%20differently%3F%20How%20can%20we%20get%20the%20.xls%20to%20show%20up%3F%3C%2FSTRONG%3E%3C%2FP%3E%3CHR%20%2F%3E%3COL%3E%3CLI%3E%3CSTRONG%3E.pdf%3C%2FSTRONG%3E%3C%2FLI%3E%3C%2FOL%3E%3CP%3EIframe%20gets%20blocked.%3CBR%20%2F%3EIframe-URL%20is%3C%2FP%3E%3CDIV%20class%3D%22code%20panel%22%3E%3CDIV%20class%3D%22codeContent%20panelContent%22%3E%3CPRE%3Ehttps%3A%3CSPAN%20class%3D%22code-comment%22%3E%2F%2F..._layouts%2F15%2FWopiFrame.aspx%3Fsourcedoc%3D%7Bc967893a-26e4-45d9-876b-8d77d7575cc2%7D%26amp%3Baction%3Dembedview%26amp%3BwdStartOn%3D1%3C%2FSPAN%3E%3C%2FPRE%3E%3C%2FDIV%3E%3C%2FDIV%3E%3CDIV%20class%3D%22code%20panel%22%3E%3CDIV%20class%3D%22codeContent%20panelContent%22%3E%3CPRE%3E%3CSPAN%20class%3D%22code-quote%22%3E%22Refused%20to%20display%20'https%3A%3CSPAN%20class%3D%22code-comment%22%3E%2F%2F...%2FShared%20Documents%3FRootFolder%3D%252Fsites%252Fsmarterpathtestingsite%252FShared%20Documents'%3C%2FSPAN%3E%20in%20a%20frame%20because%20it%20set%20'X-Frame-Options'%20to%20'sameorigin'.%22%3C%2FSPAN%3E%3C%2FPRE%3E%3C%2FDIV%3E%3C%2FDIV%3E%3CP%3EAs%20it%20seems%20the%20URL%20doesnt%20work%20at%20all%2C%20it%20redirects%20to%20the%20Folder-View%20of%20that%20Sharepoint-Site.%20The%20same%20behavior%20when%20the%20URL%20gets%20opened%20up%20in%20the%20browser%20directly.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3EQUESTION%3A%20Is%20there%20any%20way%20to%20embed%20a%20PDF%20like%20this%3F%20In%20our%20local%20Dev%20environment%20it%20was%20working%20fine.%3C%2FSTRONG%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-213679%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EDocument%20Library%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFiles%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%20Online%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-294510%22%20slang%3D%22en-US%22%3ERe%3A%20Add-In%3A%20Embedding%20SharePoint%20content%20in%20iframe%20(xls%2C%20PDF)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-294510%22%20slang%3D%22en-US%22%3E%3CP%3EUse%20%3CSTRONG%3Einteractivepreview%3C%2FSTRONG%3Eaction%20option.%3C%2FP%3E%3CP%3EExample%3A%3C%2FP%3E%3CDIV%3E%3CDIV%3E%3CEM%3E%26amp%3Baction%3Dinteractivepreview%3C%2FEM%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CEM%3ERegards%3C%2FEM%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CEM%3ENorbz%3C%2FEM%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-213728%22%20slang%3D%22en-US%22%3ERe%3A%20Embedding%20SharePoint%20content%20in%20iframe%20(xls%2C%20PDF)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-213728%22%20slang%3D%22en-US%22%3E%3CP%3EWe%20are%20having%20a%20SharePoint%20Online%20Add-In%2C%20it%20is%20not%20about%20integrating%20in%20SharePoint%20sites.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-213683%22%20slang%3D%22en-US%22%3ERe%3A%20Embedding%20SharePoint%20content%20in%20iframe%20(xls%2C%20PDF)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-213683%22%20slang%3D%22en-US%22%3E%C2%A8Have%20you%20tried%20the%20file%20viewer%20WebPart%3F%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2242395%22%20slang%3D%22en-US%22%3ERe%3A%20Add-In%3A%20Embedding%20SharePoint%20content%20in%20iframe%20(xls%2C%20PDF)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2242395%22%20slang%3D%22en-US%22%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F22254%22%20target%3D%22_blank%22%3E%40Linda%3C%2FA%3E%20Have%20you%20tried%20this%3F%20And%20if%20yes%2C%20is%20it%20working%3F%3F%3C%2FLINGO-BODY%3E
New Contributor

We try to embed SharePoint content in an iFrame. Therefore we use the GUID of the doc to build the ifram URL.

([[HOST]‌]_layouts/15/WopiFrame.aspx?sourcedoc={[[GUID]]}&action=embedview&wdStartOn=1)

Tested with 3 different files.


  1. .pptx

Working fine.
Iframe-URL is

https://..._layouts/15/WopiFrame.aspx?sourcedoc={cfca68b9-c498-4c9b-a790-52d0f522b684}&action=embedview&wdStartOn=1

Everything is working fine. Preview is available.


  1. .xls

Iframe gets blocked.
Iframe-URL is

https://..._layouts/15/WopiFrame.aspx?sourcedoc={51bf3f39-addc-48aa-b9a0-7bd1b56d9f07}&action=embedview&wdStartOn=1

Browser shows the following message:

Refused to display 'https://..._layouts/15/WopiFrame.aspx?sourcedoc={51bf3f39-addc-48aa-b9a0-7bd1b56d9f07}&action=embedview&wdStartOn=1' in a frame because it set 'X-Frame-Options' to 'sameorigin'.

Its exactly the same URL as before, just the query parameters are different (different GUIDs).
When URLs get opened directly in the browser, you can see a small redirect. 
The PPTX gets redirected to https://xyz.sharepoint.com‌/:p/r/‌sites/.../_layouts/15/WopiFrame.aspx?....
The XLS gets redirected to https://xyz.sharepoint.com‌/:x/r/‌sites/.../_layouts/15/WopiFrame.aspx?....

 

QUESTION: Why does it get handled differently? How can we get the .xls to show up?


  1. .pdf

Iframe gets blocked.
Iframe-URL is

https://..._layouts/15/WopiFrame.aspx?sourcedoc={c967893a-26e4-45d9-876b-8d77d7575cc2}&action=embedview&wdStartOn=1
"Refused to display 'https://.../Shared Documents?RootFolder=%2Fsites%2Fsmarterpathtestingsite%2FShared Documents' in a frame because it set 'X-Frame-Options' to 'sameorigin'."

As it seems the URL doesnt work at all, it redirects to the Folder-View of that Sharepoint-Site. The same behavior when the URL gets opened up in the browser directly.

 

QUESTION: Is there any way to embed a PDF like this? In our local Dev environment it was working fine.

4 Replies
¨Have you tried the file viewer WebPart?

We are having a SharePoint Online Add-In, it is not about integrating in SharePoint sites.

Use interactivepreview action option.

Example:

&action=interactivepreview
 
Regards
 
Norbz

@Linda Werner  Have you tried this? And if yes, is it working??