仿真 /绕过以下内容:文件选择器对话框只能通过用户激活显示
我知道此消息告诉我问题...但是我只是在一个小型有趣的项目中弄乱,并想删除页面加载时打开文件输入所需的额外点击。
以下(和jsfiddle https://jsfiddle.net/qu52ksef/
<label id="foo" for="input">Open</label>
<input id="input" name="input" type="file">
<script>
ready(function() {
document.querySelector("#foo").click();
});
function ready(fn) {
if (document.readyState != 'loading'){
fn();
} else {
document.addEventListener('DOMContentLoaded', fn);
}
}
</script>
) :只能通过用户激活显示文件选择器对话框。
无论如何,是否可以通过此检查作为一种“ hack”?这不会只是我正在玩的一个小宠物项目。
谢谢,
I know this message is telling me the problem... but I'm just messing around with a small fun project and would like to remove the extra click that's required to open a file input when the page loads.
The following (and jsfiddle https://jsfiddle.net/qu52ksef/)
<label id="foo" for="input">Open</label>
<input id="input" name="input" type="file">
<script>
ready(function() {
document.querySelector("#foo").click();
});
function ready(fn) {
if (document.readyState != 'loading'){
fn();
} else {
document.addEventListener('DOMContentLoaded', fn);
}
}
</script>
This will fire the following in Chrome: File chooser dialog can only be shown with a user activation.
Is there anyway to by pass this check as a sort of 'hack'?. This won't be going into production just a little pet project I'm playing with.
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用它
use it