API window.showDirectoryPicker在所有基于Chromium的浏览器上都能正常工作。Firefox目前还没有这样的API。有什么变通办法吗?Firefox有文件和目录句柄的API,但没有选择器对话框,这很奇怪。
55ooxyrt1#
您可以尝试使用https://github.com/use-strict/file-system-access/tree/master中的showDirectoryPicker ponyfill。index.html文件中的示例适用于我:
showDirectoryPicker
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>
1条答案
按热度按时间55ooxyrt1#
您可以尝试使用https://github.com/use-strict/file-system-access/tree/master中的
showDirectoryPicker
ponyfill。index.html
文件中的示例适用于我: