Bookmarklet to save file

bookmarklet, firefox

Solution

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.

Problem

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?

Original source