简体   繁体   English

在iOS 6上以编程方式触发文件输入对话框

[英]Trigger file input dialog programatically on iOS 6

How can I trigger a select file dialog on iOS 6 for an input element in the DOM programatically? 如何在iOS 6上以编程方式触发DOM中输入元素的选择文件对话框? (ie using Javascript) (即使用Javascript)

<input type="file" id="foo">

Notes: 笔记:

  • Mobile Safari and Safari seems to behave differently. 移动Safari和Safari的行为似乎有所不同。 I've got it working using document.querySelector("input[type=file]").click() in safari. 我使用safari中的document.querySelector("input[type=file]").click()使它正常工作。
  • If it's within a native clickhandler, ie initiated by the user, it seems to work, but I'd like to trigger the dialog on will. 如果它在本机clickhandler内,即由用户启动,则似乎可行,但我想按意愿触发对话框。

After some more research it seems like this isn't possible. 经过更多研究后,看来这是不可能的。 Least I haven't found a method that works. 至少我还没有找到一种有效的方法。

I decided to solve this using an <input type='file'> positioned on top of the button, with opacity 0.01 to make the button visible. 我决定使用位于按钮顶部的<input type='file'> (不透明度0.01)使按钮可见来解决此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM