views:

559

answers:

1

I have a legacy application that, at some point, generates the following code in one of its pages:

window.location.href = "http://localhost:8080/myApplication/manuals/charts.xls";

When Mozilla sees this, it opens a download dialog with "open with...\save as..." options.

IE (v7 and v8) does not open a dialog. It takes the file and just renders it in the page, like some HTML; but it's a binary file, so all you see is garbage on the screen.

Has anyone encountered this before?

EDIT1: This works on some IE browser but not on all. I am thinking a configuration issue with IE. Also, for .ppt and .doc files it works, the issue is just for .xls files.

EDIT2: Even if I place a link in the page like:

click <a href="http://localhost:8080/myApplication/manuals/charts.xls"&gt;here&lt;/a&gt; for the XLS

it won’t display the dialog box when I click on it. It just gets written in the page.

A: 

You need to make sure your web server is sending the correct MIME type for the xls file.

Look for a directory WEB-INF with a file web.xml. Add this to the file, within the web-app element:

<mime-mapping>
  <extension>xls</extension>
  <mime-type>application/octet-stream</mime-type>
</mime-mapping>
Jeremy Stein
This file sits on the server, in the "manuals" folder in the application's context directory. It is accessed as presented in the question. Even if I enter "http://localhost:8080/myApplication/manuals/charts.xls" in IE's address bar I still get garbage on the screen instead of a download dialog. I can’t set "Content-disposition" headers, it's just like a link.
dpb
The Content-disposition header will be set by your web server. Are you using IIS? Apache? Tomcat?
Jeremy Stein
I am using OC4J
dpb
OK, I added instructions for configuring the mime-type.
Jeremy Stein
That did the trick. Thank you.
dpb