在不离开页面的情况下打开下载窗口的最简单方法 [英] easiest way to open a download window without navigating away from the page

查看:134
本文介绍了在不离开页面的情况下打开下载窗口的最简单方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

打开下载对话框的最佳跨浏览器方式是什么(假设我们可以设置内容处理:标题中的附件)而无需导航离开当前页面,或打开弹出窗口,这在IE6中无效。

What is the best cross browser way to open a download dialog (lets assume we can set content-disposion:attachment in the headers) without navigating away from the current page, or opening popups, which doesnt work well in IE6.

推荐答案

7年过去了,好的。
我不知道是否适用于IE6,但这会在FF和Chrome中提示OpenFileDialog。

7 years have passed, ok. I don't know is it work for IE6, but this prompts OpenFileDialog in FF and Chrome.

var file_path = 'host/path/file.ext';
var a = document.createElement('A');
a.href = file_path;
a.download = file_path.substr(file_path.lastIndexOf('/') + 1);
document.body.appendChild(a);
a.click();
document.body.removeChild(a);

这篇关于在不离开页面的情况下打开下载窗口的最简单方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆