2

I need to show a html file on a modern sharepoint site. Wiki or webpart, right now, doesn't matter. I don't want to allow all users to add custom code, so putting the file as aspx in the site pages folder will not work. Page Viewer web part tries to download the html file. Is there any other option? The file is created with MindManager. I don't know the tool, but based on a quick search their viewer only works with on premise SP.

3 Answers 3

2

I have not tested below solution yet.

There is a SPFx webpart (works on modern pages) available on github by Microsoft called react-script-editor. You can install this webpart to your site collection and then use below code to insert the html into an iframe.

<script language="javascript" type="text/javascript">
 $(document).ready(function(){
       $("#iframeContainer").attr("src","https://siteurl/page.html");
 });
</script>

<iframe  id="iframeContainer" src=""></iframe>
1

If you have a classic SharePoint site, you can use a content editor web part. If the site is a modern site, there aren't options that I'm aware of for this.

For a classic site, simply upload the file to a library, and then on a SharePoint page, edit the page, add the content editor web part, and in the web part properties, put in the path to the html file in the library. Full documentation for this web part

0
0

You could limit your users to only be able to READ that page (no edit).

Also there's a webpart in modern view (SPO) that allows you to embed things. I actually use one right now to iframe a page on another site collection that i have. The webpart is called "Embed" and you can add your code to it.

Update with what i added in the webpart-> :

<iframe src="https://SPSITE.sharepoint.com/teams/MYSITE/SiteAssets/FOLDER/PAGE.aspx" width="400" height="630"> 
</iframe>
5
  • 1
    I tried the embed webpart too, when I add the link to the html file it also tries to download instead of showing it.
    – vilmarci
    Aug 31, 2018 at 17:35
  • Did you use the iframe code or just added the link? Check this out - w3schools.com/tags/tag_iframe.asp ( updated my answer)
    – Dante R.
    Aug 31, 2018 at 18:07
  • 1
    Yes, I am using the embed code. The html file wants to be downloaded, if I rename to aspx, I get a "something went wrong" error without any explanation.
    – vilmarci
    Aug 31, 2018 at 18:24
  • That error might be because of a sharepoint thingy that doesnt allow iframes. Add this to your ASPX page - <WebPartPages:AllowFraming runat="server" /> and give it a try.
    – Dante R.
    Aug 31, 2018 at 18:35
  • I have the same problem. Whatever I use a HTML or ASPX file, SPO will force it to be downloaded instead of loading it...
    – AymKdn
    Dec 20, 2019 at 9:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.