homepage Welcome to WebmasterWorld Guest from 54.205.207.53
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Allowing visitor to view external JavaScript file
Should type="text/plain" enable this?
NickH

10+ Year Member



 
Msg#: 533 posted 10:38 pm on Aug 13, 2003 (gmt 0)

I'd like to offer the visitor the chance to view an external JavaScript file. This would be via a link in the HTML document in which the JS is used. However, no matter what mimetype I try, IE6 offers the file download prompt. Mozilla and Opera display the JS file, as I want.

So I have two questions:

  1. Is setting type="text/plain" supposed to indicate to the UA to display the contents as plain text?
  2. If so, is there a workaround for IE? (I'd rather not take a copy of the file, and give it a .txt extension.)
Nick

 

gph

10+ Year Member



 
Msg#: 533 posted 12:23 am on Aug 14, 2003 (gmt 0)

1. Is setting type="text/plain" supposed to indicate to the UA to display the contents as plain text?

Sorry, I don't know. it looks like it should.

2. If so, is there a workaround for IE? (I'd rather not take a copy of the file, and give it a .txt extension.)

Strange as it may seem, the file extension is irrelevant. You can name a script src="script.blah" and browsers will parse it as js (don't ask me why).

<edit>that's within script tags. Your alternative of making a txt copy would probably work as expected</edit>

The only way I know of to display js in IE is to put it on a page. Hopefully someone else will have a better idea.

4serendipity

10+ Year Member



 
Msg#: 533 posted 1:37 am on Aug 14, 2003 (gmt 0)

Placing the script in a text file is certainly the easiest solution.

Another solution would be to use character entities along with the <pre> element to display your script on an HTML page.

Key_Master

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 533 posted 2:30 am on Aug 14, 2003 (gmt 0)

There is a way to force it but it's really ugly. Place the following in your .htaccess file.

AddType text/x-server-parsed-html js

*Or*

Use Javascript to detect IE and replace your link with:

view-source:http://www.example.com/javascript-file.js

This will open the Javascript file in Notepad or whatever the default editor is. view-source only works with IE and newer versions of Netscape.

BjarneDM

10+ Year Member



 
Msg#: 533 posted 10:55 am on Aug 19, 2003 (gmt 0)

In my experience it seems as if IE in many cases don't care about the content-type instead relying upon analysing what is received. I've had this issue with some php-generated *.jpgs that were sent with content-type text/plain. Mozilla et al displayed these as text while IE displayed them as a pictures. The special thing about these pictures was that they didn't have any *.jpg-suffix, so no clue was presented to the browser as to the correct filetype except by analysing the stream.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved