Welcome to WebmasterWorld Guest from 23.20.18.183

Forum Moderators: open

Message Too Old, No Replies

Allowing visitor to view external JavaScript file

Should type="text/plain" enable this?

     
10:38 pm on Aug 13, 2003 (gmt 0)

Junior Member

10+ Year Member

joined:Jan 8, 2003
posts:81
votes: 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

12:23 am on Aug 14, 2003 (gmt 0)

Full Member

10+ Year Member

joined:Jan 31, 2002
posts:285
votes: 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.

1:37 am on Aug 14, 2003 (gmt 0)

Full Member

10+ Year Member

joined:Jan 5, 2003
posts:202
votes: 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.

2:30 am on Aug 14, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 27, 2001
posts:1472
votes: 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.

10:55 am on Aug 19, 2003 (gmt 0)

Full Member

10+ Year Member

joined:Dec 22, 2002
posts:334
votes: 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.