By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,498 Members | 1,564 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,498 IT Pros & Developers. It's quick & easy.

How to display plain text files containing javascript code?

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
"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.