472,110 Members | 2,097 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,110 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 4011
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Nick | last post: by
4 posts views Thread by MCDONAMW | last post: by
5 posts views Thread by Peter Lapic | last post: by
3 posts views Thread by jiayanxiang | last post: by
2 posts views Thread by David Virgil Hobbs | last post: by
reply views Thread by leo001 | last post: by

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.