I am trying to embed an html file in a page.
I use the following code:
<iframe src="{{resource.previewUrl}}" allowfullscreen webkitallowfullscreen mozallowfullscreen height="700" width="100%" frameborder="0" marginheight="0" marginwidth="0" ></iframe>
The source I get through angular is the address to the index.html file which is in Azure blob storage:
_sc.resource.previewUrl = $sce.trustAsResourceUrl("http://portalxxxxxxx.blob.core.windows.net/path/to/index.html");
When I open the page, it downloads the index.html file to my computer instead of displaying it. How can I force it to display?
There are tens of reasons which can cause this issue of downloading files instead of opening in browser. But mainly you get this issue due to poor hosting provider, any deflect in cache plugin you're using on your website, or you messed up with the . htaccess file.
An iframe, short for inline frame, is an HTML element that contains another HTML document within it. The iframe element is specified with the iframe tag. It may be placed anywhere in an HTML document, and thus anywhere on a web page.
Deprecated AttributesSome attributes from HTML4 are no longer allowed in HTML5 at all and they have been removed completely. img and iframe.
The problem is because of the content-type property of the blob. If content-type property of a blob is not set explicitly, Azure Blob storage assigns application/octet-stream
.
In your case because you're not setting this property, even for your HTML files, the content type is set as default value i.e. application/octet-stream
. Because the browser (especially Chrome) does not understand how to deal with this content type, it downloads it instead of rendering it.
Changing the content type of the blob to text/html
should fix the problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With