473,324 Members | 2,370 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

How to display plain text files containing javascript code?

I want to display plain text files in the browser. The files contain html and javascript and have a .txt extension.

This works fine with files with just html. Unfortunately when showing files with javascript, I get an "error on page" warning and the page is not displayed. I suppose that when Internet Explorer discovers a <script> tag he starts to interpret it. This is not what I want. After all Internet Explorer is a browser and not an interpreter.

Can anybody tell me, or refer me to some documentation, about the reason why Internet Explorer is not just displaying plain text files as they are.

How can I send plain text files to the client and tell the browser: do not interpret this page, just display it. I suppose it has got something to do with MIME types but i am not sure

A workaround would be welcome aswell.

I discovered that everything between <textarea></textarea> tags is displayed as it is (even other tags) but I prefer to display the file itself

With kind regard

Hok
Jul 19 '05 #1
4 4100
How are you referencing the page? Is it an include file? Are you loading
it directly, as in http://mydomain.com/mytextfile.txt?

"hoke" <an*******@discussions.microsoft.com> wrote in message
news:D2**********************************@microsof t.com...
I want to display plain text files in the browser. The files contain html and javascript and have a .txt extension.
This works fine with files with just html. Unfortunately when showing files with javascript, I get an "error on page" warning and the page is not
displayed. I suppose that when Internet Explorer discovers a <script> tag he
starts to interpret it. This is not what I want. After all Internet Explorer
is a browser and not an interpreter.
Can anybody tell me, or refer me to some documentation, about the reason why Internet Explorer is not just displaying plain text files as they are.
How can I send plain text files to the client and tell the browser: do not interpret this page, just display it. I suppose it has got something to do
with MIME types but i am not sure.
A workaround would be welcome aswell.

I discovered that everything between <textarea></textarea> tags is displayed as it is (even other tags) but I prefer to display the file
itself.
With kind regards

Hoke

Jul 19 '05 #2
I am loading it directly like this http://holke.mine.nu/gemini-it/secti...ate-block.txt).

Later I will try it with redirect like response.Redirect("create-block.txt")
Jul 19 '05 #3
hoke wrote:
I want to display plain text files in the browser. The files contain
html and javascript and have a .txt extension.

This works fine with files with just html. Unfortunately when showing
files with javascript, I get an "error on page" warning and the page
is not displayed. I suppose that when Internet Explorer discovers a
<script> tag he starts to interpret it. This is not what I want.
After all Internet Explorer is a browser and not an interpreter.

Can anybody tell me, or refer me to some documentation, about the
reason why Internet Explorer is not just displaying plain text files
as they are.

How can I send plain text files to the client and tell the browser:
do not interpret this page, just display it. I suppose it has got
something to do with MIME types but i am not sure.

A workaround would be welcome aswell.

I discovered that everything between <textarea></textarea> tags is
displayed as it is (even other tags) but I prefer to display the file
itself.

With kind regards

Hoke


Does your process allow you to use HTMLEncode() on the contents of the text
file before sending it to the response?

Bob Barrows

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jul 19 '05 #4
"hoke" wrote:
: I want to display plain text files in the browser. The files contain html
and javascript and have a .txt extension.
:
: This works fine with files with just html. Unfortunately when showing
files with javascript, I get an "error on page" warning and the page is not
displayed. I suppose that when Internet Explorer discovers a <script> tag he
starts to interpret it. This is not what I want. After all Internet Explorer
is a browser and not an interpreter.
:
: Can anybody tell me, or refer me to some documentation, about the reason
why Internet Explorer is not just displaying plain text files as they are.
:
: How can I send plain text files to the client and tell the browser: do not
interpret this page, just display it. I suppose it has got something to do
with MIME types but i am not sure.
:
: A workaround would be welcome aswell.
:
: I discovered that everything between <textarea></textarea> tags is
displayed as it is (even other tags) but I prefer to display the file
itself.

Hoke...

You do not need to save an additional version of your server-side code with
..txt.

Just use this to view the original source. Change the file name from
somefile.asp to your file and include a path to get there if it is not in
the same directory. I usually save this file with a prefix to the original
source file name, i.e. ss_somefile.asp.
DO NOT modify this file to pass arguments to it because that will allow
anyone to view any file you have.

<%@ Language=VBScript %>
<%
Dim strURL
strURL = "somefile.asp"
Dim strDir, strFileName
strDir = Request.ServerVariables("APPL_PHYSICAL_PATH")
strFileName = Replace(strURL,"/","\")
strFileName = strDir & strFileName

Const ForReading = 1
Dim objFSO, objTextStream
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objTextStream = objFSO.OpenTextFile(strFileName, ForReading)

Response.Write "<HTML><BODY>"
Response.Write "<XMP>" & objTextStream.ReadAll & ""
Response.Write ""
objTextStream.Close
Set objTextStream = Nothing
Set objFSO = Nothing
%>

HTH...

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Dan R Brown | last post by:
I have a large form that is generated dynamically in a jsp using xml / xslt. So, to break up this form into several "tabbed" sections, I break up the form using <div> tags. Each <div...
4
by: Nick | last post by:
I would like to have a errorMessage displayed in a webpage. When a function is called the text changes. My code below replaces the html page with the errorMessage instead of embedding it into the...
6
by: Sandman | last post by:
I'm having some problem here... I have a javascript I've downloaded that goes through all PNG files and enables the transparency channel in them for IE5.5+ by converting them to SPAN layers with...
4
by: MCDONAMW | last post by:
First off, forgive me for being such a noob. I typically program vb.net, but I need to do some asp.net programming. I have something simple I have no idea how to do! I have an aspx page which...
7
by: TLM | last post by:
I am trying to build a web application that will contain links to files on a users local computer. I am assuming that the files will be in a known location and can display in a browser window. ...
5
by: Peter Lapic | last post by:
I have to create a image web service that when it receives an imageid parameter it will return a gif image from a file that has been stored on the server. The client will be an asp.net web page...
3
by: jiayanxiang | last post by:
Is there any sample code to use Javascript to load and display a text file? It will be best if the user can select files using some kind of explorer. If that's complex, a text box to specify the...
2
by: David Virgil Hobbs | last post by:
Loading text strings containing HTML code into an HTML parser in a Javascript/Jscript I would like to know, how one would go about loading a text string containing HTML code, so as to be able to...
1
by: _Who | last post by:
I wonder if you can explain what is going on? In vs browser, if I click, a window opens and the file is displayed. But I copy the files to the ips and click and get: Line 0 Object expected ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.