Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why .txt file in <iframe> is getting downloaded instead of displayed?

I am using an <iframe> to display a text file:

<div class="document-view">
    <img src="img/302.GIF" />
</div> 

$(window).load(function () {
    <s:if test="extention.equalsIgnoreCase('txt')">
      element = '<iframe class="iframe" src="/dmsrepo/<s:property value="docLocation"/>" />';
    </s:if>

    $('.document-view').html(element);
});

When I inspect element in the browser I can see the file location.

<iframe class="iframe" src="/dmsrepo/Legal Doc Type/LegalDocType_123456789_1.0.txt" />

But the text file is getting downloaded in Chrome, Firefox and IE.

How to resolve this issue?


EDIT: you can reproduce the behavior in the following fiddle, that strangely affects only Firefox, for every page load after the first one.

Simply open the page, then press Run.

Note: it affects also the first load if Firebug Net module is activated.

like image 435
Prince Radhakrishnan Avatar asked Jun 16 '15 07:06

Prince Radhakrishnan


1 Answers

to display file add below line(s) in .htaccess

AddType text/plain .txt
AddType text/plain .log

This is signal Firefox that you don't have to download the file instead view file as plain text.This technique can be applied to all the files that you need to view instead off download.

like image 190
Azmat Karim Khan Avatar answered Sep 28 '22 05:09

Azmat Karim Khan