Leah Zorychta
Leah Zorychta

Reputation: 13419

.click not working in 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.

Upvotes: 2

Views: 1020

Answers (2)

xmarcos
xmarcos

Reputation: 3368

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?

Upvotes: 2

elios264
elios264

Reputation: 395

is because the browser blocks pop-ups, at least in firefox tells me a pop-up blocking

Upvotes: 1

Related Questions