So, I want people to be able to click on the link, and the input box with the file will open. But I want this to happen if the browser supports it. As stated in this answer , chrome supports this. Firefox 3.6 does not work, but Firefox 4 should .
I know that you can often test feature support in javascript, but I'm not sure how to test this feature.
If you want to see what I mean, the code below shows this function when you click on the link. You can also play with this on my page .
<html lang="en">
<head>
<meta charset="utf-8">
<title>Upload Field Click Test</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
var clicker = document.getElementById('clicker');
var uploader = document.getElementById('uploader');
clicker.addEventListener("click", function(e) {
uploader.click();
e.preventDefault();
}, false);
});
</script>
</head>
<body>
<form>
<input type="file" id="uploader">
</form>
<a href="#" id="clicker">Should click the uploader</a>
</body>
</html>
Things that don't work:
- testing! uploader.click
- view if uploader.click () throws an exception