window.location.href does not work in Internet Explorer with XLS files
-
19-09-2019 - |
Question
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">here</a> for the XLS
it won’t display the dialog box when I click on it. It just gets written in the page.
Solution
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>