PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, October 16, 2022

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

 October 16, 2022     download, firefox, html, iframe, struts2     No comments   

Issue

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.


Solution

This is the issue with the file. it is not formatted as html. because it has some special unicode (eg) characters at end of file read. if text response has special character like that. it failed to parse response as html embedded in iframe.

you can check this example :

<iframe src='http://humanstxt.org/humans.txt' /> </iframe> 



Answered By - Paraneetharan Saravanaperumal
Answer Checked By - Pedro (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing