0

Given a URL like: http:// host:port/app/whatever.js

IE(Internet Explorer) attempts to download whatever.js, instead of rendering(or executing) it on the browser. I am using IE8/WinXP

How can i make IE render(/execute) the .js instead (of prompting for a download)?

(On FireFox/Chrome whatever.js is rendered correctly, but not in IE.)

Jasper
  • 7,524
  • 24
  • 87
  • 131
  • http://stackoverflow.com/questions/2483771/how-can-i-convince-ie-to-simply-display-application-json-rather-than-offer-to-do – Matt Zeunert Feb 04 '13 at 10:51
  • 1
    Serve it with a supported `Content-Type`: http://stackoverflow.com/a/7227303/855543 – PointedEars Feb 04 '13 at 11:00
  • Matt> That is JSON example. How do i do that for JavaScript? PointedEars> The Javascript is a static javascript hosted by someone else, so i can't really make changes to it. Also i checked in fiddler the response header is already: application/javascript (as expected) – Jasper Feb 04 '13 at 12:29

1 Answers1

2

I realized that the behavior that IE is exhibiting is correct - thats the default behavior. IE will prompt for .js file to be downloaded if you give URL of .js directly in the browser bar.

But if the .js is invoked via HTML <script src="whatever.js"> tag, then the JavaScript is executed.

Therefore, there isn't really a case for .js to be rendered.

Jasper
  • 7,524
  • 24
  • 87
  • 131
  • Firefox and Chrome and other browsers will display a .js file directly in the browser if you navigate to it directly which is very handy (especially as a developer). Having it download is annoying. I was hoping there would be an answer to this. Forcing download may be the 'default' behaviour by this bad browser, but I'm not sure I'd say it's 'correct'. It's just yet another small but annoying reason IE is hated by everyone. – Manachi May 06 '16 at 01:45