473,549 Members | 2,651 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4117
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*******@disc ussions.microso ft.com> wrote in message
news:D2******** *************** ***********@mic rosoft.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.Redire ct("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=VBScri pt %>
<%
Dim strURL
strURL = "somefile.a sp"
Dim strDir, strFileName
strDir = Request.ServerV ariables("APPL_ PHYSICAL_PATH")
strFileName = Replace(strURL, "/","\")
strFileName = strDir & strFileName

Const ForReading = 1
Dim objFSO, objTextStream
Set objFSO = Server.CreateOb ject("Scripting .FileSystemObje ct")
Set objTextStream = objFSO.OpenText File(strFileNam e, ForReading)

Response.Write "<HTML><BOD Y>"
Response.Write "<XMP>" & objTextStream.R eadAll & ""
Response.Write ""
objTextStream.C lose
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
40646
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 style="display:none"> can be displayed by setting the style attribute to "display:", or hidden with "display:none". This gives the illusion that the person...
4
5085
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 html code. Its a stripped down version of the actual code but contains the same 3 pieces: An action to validate a form, the function to check if the...
6
6192
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 the image as background. This works great until I put one of these PNG files inside a display:none block and later sets the block to...
4
5399
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 is essentially a form containing a few text boxes and a submit button. The user types in the various fields, and hits the submit button. This...
7
6369
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. I have my ASP.NET application building links along the lines of file://c:/<path to file>
5
5020
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 that calls the web service to render a vertical strip of images. After doing some research I am unable to find some vb.net code that can assist...
3
3882
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 file name will be fine as well. Once a text file is selected, I just need to display it in a text box. Thanks for the help.
2
2655
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 use javascript or Jscript to work with the HTML code in the text string, in the same way that one works with XML code in a text string using the...
1
1118
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 debug produces only this: openWindow('Sharbel','Images/Sharbel.jpg',470+30,485+30)
0
7532
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7975
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7492
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6059
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5381
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3510
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1957
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1069
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
777
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.