.click 在 Chrome 中不起作用
我的代码示例如下: http://develop.davzy.com/test2.php
<input name="avatarfile" type="file" id='uploadbutton' />
<script>document.getElementById("uploadbutton").click()</script>
当您打开页面时,它应该立即打开文件选择器。它适用于 IE8、IE9、FireFox,但不适用于 Chrome。
A sample of my code is here: http://develop.davzy.com/test2.php
<input name="avatarfile" type="file" id='uploadbutton' />
<script>document.getElementById("uploadbutton").click()</script>
It is supposed to open the file selector as soon as you open the page. It works in IE8, IE9, FireFox, but not in Chrome.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它不起作用,即使在 Firefox (7+) 中也是如此。这是避免输入字段被劫持的安全措施。
关于弹出窗口,Firefox 会警告您页面正在尝试在页面加载时弹出一个窗口(文件上传对话框是一个 ui 窗口),因此用户会收到通知并可以选择允许或阻止它。
无论如何,为什么需要在页面加载时打开文件对话框?
It won't work, not even in Firefox (7+). It's a security measure to avoid hijacking of the input field.
Regarding the pop up, Firefox warns you that the page is trying to pop up a window (the file upload dialog is an ui window) on page load, so the user is notified and is given the choice to allow it or block it.
Anyway, why would you need to open an file dialog on page load?
是因为浏览器阻止了弹出窗口,至少在firefox中告诉我阻止了弹出窗口
is because the browser blocks pop-ups, at least in firefox tells me a pop-up blocking