Clear iOS 6 <input type=file> image thumbnai

2019-06-27 07:29发布

问题:

Since iOS 6 it is possible to use the <input type='file'> to access the photo library. I use this to upload images to a wall, through an UIWebView. Works fine.

The input element is kinda nicely implemented by Apple, with a small auto-generated thumbnail between the button and the filename field.

My only problem around this is that I cannot seem to reset this thumbnail. If it set the .value of the input to null, the filename clears out ("no file selected", as stated initially) but the thumbnail remains. Same thing if I try to .reset() the html form encapsulating the input. The small image won't go away!

Anyone know how to achieve this?

回答1:

I am able to have reset work on the containing form. I just did a simple test on my device using webkit inspector attached to it.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <title>upload</title>
    <style>
    html, body {
        width: 300px;
    }
    </style>
</head>
<body>

<form id="con">
<input id="tgt" type="file" />
</form>

</body>
</html>

I used the simple html above, then the following javascript in the inspector:

var con = document.getElementById('con');
con.reset();

Using that removed the thumbnail image for me. I've included an example with inline code here: http://www.mixicon.com/downloads/input.html