Chrome 在Firefox中使用window.showDirectoryPicker的任何解决方法

hc2pp10m  于 12个月前  发布在  Go
关注(0)|答案(1)|浏览(266)

API window.showDirectoryPicker在所有基于Chromium的浏览器上都能正常工作。
Firefox目前还没有这样的API。有什么变通办法吗?
Firefox有文件和目录句柄的API,但没有选择器对话框,这很奇怪。

55ooxyrt

55ooxyrt1#

您可以尝试使用https://github.com/use-strict/file-system-access/tree/master中的showDirectoryPicker ponyfill。
index.html文件中的示例适用于我:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />

        <meta http-equiv="X-UA-Compatible" content="ie=edge" />
        <title>HTML 5 Boilerplate</title>
    </head>
    <body>
        <button onClick="showPicker()">Click mee</button>
        <script type="module">
            import { showDirectoryPicker } from 'https://cdn.jsdelivr.net/npm/file-system-access/lib/es2018.js';
            const showPicker = async () => {
                try {
                    const handle = await showDirectoryPicker();
                    console.log(handle);
                } catch (e) {
                    console.log(e);
                }
            };
            window.showPicker = showPicker;
        </script>
    </body>
</html>

相关问题