How to display plain text files containing javascript code?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • hoke

    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


  • William Morris

    #2
    Re: How to display plain text files containing javascript code?

    How are you referencing the page? Is it an include file? Are you loading
    it directly, as in http://mydomain.com/mytextfile.txt?

    "hoke" <anonymous@disc ussions.microso ft.com> wrote in message
    news:D2AD9F50-385D-4F60-873F-0BA3F5CF28A5@mi crosoft.com...[color=blue]
    > I want to display plain text files in the browser. The files contain html[/color]
    and javascript and have a .txt extension.[color=blue]
    >
    > This works fine with files with just html. Unfortunately when showing[/color]
    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.[color=blue]
    >
    > Can anybody tell me, or refer me to some documentation, about the reason[/color]
    why Internet Explorer is not just displaying plain text files as they are.[color=blue]
    >
    > How can I send plain text files to the client and tell the browser: do not[/color]
    interpret this page, just display it. I suppose it has got something to do
    with MIME types but i am not sure.[color=blue]
    >
    > A workaround would be welcome aswell.
    >
    > I discovered that everything between <textarea></textarea> tags is[/color]
    displayed as it is (even other tags) but I prefer to display the file
    itself.[color=blue]
    >
    > With kind regards
    >
    > Hoke
    >
    >
    >[/color]


    Comment

    • hoke

      #3
      Re: How to display plain text files containing javascript code?

      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")


      Comment

      • Bob Barrows

        #4
        Re: How to display plain text files containing javascript code?

        hoke wrote:[color=blue]
        > 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[/color]

        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.


        Comment

        • Roland Hall

          #5
          Re: How to display plain text files containing javascript code?

          "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


          Comment

          Working...