书签保存文件 [英] Bookmarklet to save file

查看:148
本文介绍了书签保存文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



许多bookmarklet打开一个页面,点击一个链接即可下载结果。例如。使用blob链接。是否可以避免这种额外的点击并直接调用保存文件/打开文件对话框?

解决方案

触发任何资源( blob: http:,无论允许的方案)的另存为对话框,使用< a href =http://www.whatwg.org/specs/web-apps/current-work/multipage/links.html#downloading-resources> download 属性一个锚的。这是从Firefox 20以来的支持。


$ b 示例:一个书签,提供当前页面作为下载:

<$ p $($)$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $。 download ='filename.html';
document.body.appendChild(a);
a.click();
a.parentNode.removeChild(a);
}) ();

要触发打开对话框,请创建< input type =file> click()它。有关许多示例,请参阅使用来自Web应用程序的文件


Is is possible to use a bookmarklet in Firefox to save/open a file directly?

Many bookmarklets open a page on which one can click on a link to download the result. E.g. using a blob link. Is it possible to avoid this extra click and invoke the "save file" / "open file" dialog directly?

解决方案

To trigger the "Save As" dialog for any resource (blob:, http:, whatever permitted scheme), use the download attribute of an anchor. This is supported since Firefox 20.

Example: A bookmarklet that presents the current page as a download:

javascript:(function() {
    var a = document.createElement('a');
    a.href = location.href;
    a.download = 'filename.html';
    document.body.appendChild(a);
    a.click();
    a.parentNode.removeChild(a);
})();

To trigger the Open dialog, create an <input type="file">, and click() it. For many examples, see Using files from web applications.

这篇关于书签保存文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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