MaineCoder
MaineCoder

Reputation: 159

Opening Word Document Link in Word without .doc extension (redirect)

I'm wondering if this is possible without resorting to some convoluted workaround. I have links that reference document management system locations (without a .doc extension). These links, since they lack the extension, open in Internet Explorer, which in turn opens a download dialog. This causes Word not to handle the opening of the document, which causes some minor end-user problems (extended launch time, etc).

Is there any way to automatically redirect the link to Microsoft Word? I found a workaround where links are 'marked' and then opened by JavaScript into Word using Active X - but this is not ideal. As far as I know there is no way to identify a "type" so that the link opens as if it has the .doc extensions (ie: <a href="***" type=".doc">~</a>). Ideally I would just want a more "native" way to open the links in Word rather than in IE.

Upvotes: 0

Views: 7121

Answers (2)

denjello
denjello

Reputation: 541

I know you said you can only use html, css and javascript, but I thought for completeness sake I would include a couple traditional routes like htaccess and php. The last three are javascript solutions, my bet is that number 5 is the one that will most likely work for you. Number 4 will be blocked by pop-up blockers and number 3 doesn't really send any headers...

1) .htaccess (placed in the folder where the files are stored)

<Files *.*>
    ForceType application/octet-stream
    Header set Content-Disposition attachment
</Files>

2) with php you would set headers for each file

header("Content-disposition: attachment; filename=msword_doc");
header("Content-type: application/msword");
readfile("msword_doc")

3) iframe

<iframe id="iframe" src="" style="display:none"></iframe>
<script>
    var frame = document.getElementById("iframe");
    window.onload = setTimeout(function(){
        frame.src="/directory/msword_doc";
    },100);
</script>

4) window.open

<script>
    window.open("/documents/msword_doc");
</script>

5) xmlhttprequest

<script>
    var client = new XMLHttpRequest();
    client.open('GET', '/documents/msword_doc');
    client.setRequestHeader('Content-disposition', 'attachment');
    client.setRequestHeader('Content-type', 'application/msword');
    client.send();
</script>

On a sidenote: NOT ALL word documents use the same mime-type - so your mileage will probably vary.

Upvotes: 1

pixelearth
pixelearth

Reputation: 14610

I'm afraid you'll either have to send the proper mime type (application/msword) or at a minimum make the file accessible at the proper extenstion (.doc). If you have no control over the system then you're SOL.

Have you actually tried with the .doc extension? I imagine you have, but some systems are set up to handle several, even arbitrary extensions that basically tell the back end what format is desired. And it will then send that format back with the proper mime types, etc.

Upvotes: 0

Related Questions