The Instructure Community will enter a read-only state on November 22, 2025 as we prepare to migrate to our new Community platform in early December. Read our blog post for more info about this change.
Hi, I'm having trouble embedding an <iframe> in a Canvas Page to display an external formsite form for students. I have reviewed Embed Code Not Working and think I was close, but the result just displays the <script> from the html file? Snippet and steps below.
My steps:
Snippet
<p><iframe src="https://gordon.instructure.com/courses/346/files/117597/preview" width="100%" height="800" data-api-endpoint="https://gordon.instructure.com/api/v1/courses/346/files/117597" data-api-returntype="File"></iframe></p>
Maybe I'm missing something obvious in the code?
You cannot display a lot of websites inside an iFrame. Reason being that they send an "X-Frame-Options: SAMEORIGIN" response header. This option prevents the browser from displaying iFrames that are not hosted on the same domain as the parent page.
I faced the same error when displaying youtube links. For example: https://www.youtube.com/watch?v=8WkuChVeL0s
I replaced watch?v= with embed/ so the valid link will be: https://www.youtube.com/embed/8WkuChVeL0s
It works well.
Try to apply the same rule on your case.
SAMEORIGIN
The page can only be displayed in a frame on the same origin as the page itself. The spec leaves it up to browser vendors to decide whether this option applies to the top level, the parent, or the whole chain, although it is argued that the option is not very useful unless all ancestors are also in the same origin.
Canvas has a content security policy (CSP) that Canvas administrators can enable that can prevent users from uploading JavaScript into files within Canvas. The recommended solution is to host the file on an external server rather than within Canvas itself. Embedding the content within Canvas has always been a hack.
If the CSP is the reason this doesn't work, then you may be able to disable it at the course level from the settings page. If your Canvas administrator has enabled it, they may have a location for you to host external files.
The code for the script showing up shouldn't be related to the iframe restrictions, but it could be a problem with the HTML in the file itself. If you look at the code of the file and see things like <script= instead of <script=, then the HTML got mangled by something so it's not recognizing it as HTML, but as something that should be displayed.
Community helpTo interact with Panda Bot, our automated chatbot, you need to sign up or log in:
Sign inTo interact with Panda Bot, our automated chatbot, you need to sign up or log in:
Sign in
This discussion post is outdated and has been archived. Please use the Community question forums and official documentation for the most current and accurate information.