Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iframe downloads the html source instead of displaying it

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?

like image 388
Ali Barış Uzuner Avatar asked Jun 20 '18 13:06

Ali Barış Uzuner


People also ask

Why HTML file is downloading instead of opening?

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.

Can I put HTML in an iframe?

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.

Is iframe deprecated in HTML5?

Deprecated AttributesSome attributes from HTML4 are no longer allowed in HTML5 at all and they have been removed completely. img and iframe.


1 Answers

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.

like image 154
Gaurav Mantri Avatar answered Sep 17 '22 13:09

Gaurav Mantri