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