Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
当我将其粘贴到地址栏时:“file:///C:/script.js”
Firefox 显示 js 文件的内容,但我希望显示下载对话框。
可能吗?
谢谢
好像和编程没有关系……直接按Ctrl+S
如果您想以编程方式强制下载提示:
function downloadPrompt(url) { var a = document.createElement("a"); a.href = url; a.download = a.href.substr(a.href.lastIndexOf("/") + 1); document.body.appendChild(a); a.click(); document.body.removeChild(a); }
演示http://jsfiddle.net/Sbp5M/
似乎只在谷歌浏览器中工作。