Reset file field and clear canvas

I want to add a reset link/clear canvas function to the below script that shows a thumbnail preview of image upload/file field, can anyone helo please?:

function previewImage(el,widths,limit){
	var files = el.files;
	var wrap = el.parentNode;
	var output = wrap.getElementsByClassName('imagePreview')[0];
	var allowedTypes = ['JPG','JPEG','GIF','PNG','SVG','WEBP'];


	var file = files[0];
	var imageType = /image.*/;

	// detect device
	var device = detectDevice();
	if (!{ // Since android doesn't handle file types right, do not do this check for phones
		if (!file.type.match(imageType)) {
			var description = document.createElement('p');
			description.innerHTML='<span class="KT_field_error" style="font-size:12px;font-weight:bold;">File format not accpeted. Allowed file types are '+allowedTypes.join(', ')+'</span>';
			return false;

	var img='';

	var reader = new FileReader();
	reader.onload = (function(aImg) {
		return function(e) {

			var format =';');
			format = format[0].split('/');
    		format = format[1].split('+');
			format = format[0].toUpperCase();

			// We will change this for an android
			if ({
				format ='.');
        		format = format[format.length-1].split('+');
				format = format[0].toUpperCase();

			var description = document.createElement('p');
			description.innerHTML = '';

			if (allowedTypes.indexOf(format)>=0 &&<(limit*1024*1024)){
				for (var size in widths){
					var image = document.createElement('img');
					var src =;

					image.src = src;

					image.width = widths[size];
					image.title = 'Image preview '+widths[size]+'px';

			if (>(limit*1024*1024)){
			description.innerHTML += '<span class="KT_field_error" style="font-size:12px;font-weight:bold;">Your image exceeds the file size limit of '+limit+'MB</span>';


// Detect client's device
function detectDevice(){
	var ua = navigator.userAgent;
	var brand = {
		apple: ua.match(/(iPhone|iPod|iPad)/),
		blackberry: ua.match(/BlackBerry/),
		android: ua.match(/Android/),
		microsoft: ua.match(/Windows Phone/),
		zune: ua.match(/ZuneWP7/)

	return brand;

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.