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).
我想知道如果不采用一些复杂的解决方法,这是否可行。我有链接参考文档管理系统位置(没有.doc扩展名)。这些链接由于缺少扩展名,因此在Internet Explorer中打开,然后打开下载对话框。这导致Word不处理文档的打开,这会导致一些小的最终用户问题(延长启动时间等)。
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.
有没有办法自动将链接重定向到Microsoft Word?我找到了一个解决方法,其中链接被“标记”,然后使用Active X通过JavaScript打开到Word - 但这并不理想。据我所知,没有办法识别“类型”,以便链接打开就像它具有.doc扩展名一样(即:〜)。理想情况下,我只想要一种更“原生”的方式来打开Word中的链接而不是IE中的链接。
2 个解决方案
#1
1
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...
我知道你说你只能使用html,css和javascript,但我认为为了完整起见,我会包括一些传统路线,如htaccess和php。最后三个是javascript解决方案,我敢打赌,5号是最有可能为你工作的。数字4将被弹出窗口阻止程序阻止,而数字3不会真正发送任何标题...
1) .htaccess (placed in the folder where the files are stored)
1).htaccess(放置在存储文件的文件夹中)
<Files *.*>
ForceType application/octet-stream
Header set Content-Disposition attachment
</Files>
2) with php you would set headers for each file
2)使用php,你可以为每个文件设置标题
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.
旁注:并非所有单词文档都使用相同的mime类型 - 因此您的里程可能会有所不同。
#2
0
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.
我担心你要么必须发送适当的mime类型(application / msword),要么至少使文件在适当的扩展(.doc)下可访问。如果您无法控制系统,那么您就是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.
你真的试过.doc扩展吗?我想你有,但有些系统设置为处理几个甚至是任意扩展,基本上告诉后端需要什么格式。然后它将使用适当的mime类型等返回该格式。
#1
1
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...
我知道你说你只能使用html,css和javascript,但我认为为了完整起见,我会包括一些传统路线,如htaccess和php。最后三个是javascript解决方案,我敢打赌,5号是最有可能为你工作的。数字4将被弹出窗口阻止程序阻止,而数字3不会真正发送任何标题...
1) .htaccess (placed in the folder where the files are stored)
1).htaccess(放置在存储文件的文件夹中)
<Files *.*>
ForceType application/octet-stream
Header set Content-Disposition attachment
</Files>
2) with php you would set headers for each file
2)使用php,你可以为每个文件设置标题
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.
旁注:并非所有单词文档都使用相同的mime类型 - 因此您的里程可能会有所不同。
#2
0
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.
我担心你要么必须发送适当的mime类型(application / msword),要么至少使文件在适当的扩展(.doc)下可访问。如果您无法控制系统,那么您就是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.
你真的试过.doc扩展吗?我想你有,但有些系统设置为处理几个甚至是任意扩展,基本上告诉后端需要什么格式。然后它将使用适当的mime类型等返回该格式。