Hey! Do you have any query related to front end?

Sign in Sign up

Show thumbnail on browseBack

Many times it has been found that, most of the person thinks that, if one wanna show thumbnail of image before uploading, then one has to use any server language such as: PHP, .net etc. But gonna show you code which gives you the facility to show thumbnail by jQuery before uploading. It is quiet easy to use. This is performed by new FileReader(); function.

Function works behind:

//Function to show uploaded image thumbnail with two arguments
//1.file input obj  2.DOM in which browsed image will be stored
function readURL(input, showImageIn) {
	var that = input;
	if (input.files && input.files[0]) {
		var reader = new FileReader();
		reader.onload = function (e) {
			showImageIn.find('img').attr('src', e.target.result);
				//Bring image in  middle after browser images load  
				setElementMiddle($('.inputCon span.browse'), $('.inputCon'));	

new FileReader(); function is used to read content of file. When reading is finished then reader variable stored the content of file in base:64 format, and when reader content gets loaded then, event target result stores in src of image available in imgCon div.

How to call reader function:

//Change event for input type file
	//store in variable, the Container in which default thumbnail in present
	var showImageBlock = $('.thumbnailCon .imgCon');
	//Call readURL function to read uploaded file
	//Pass file input as first argument and container having image as second argument
	readURL(this, showImageBlock);

How to comment:

  • Create an account in discuss by clicking on login next to arrow.
  • Create password for discuss and varify your email id, through your mail.
  • Refresh page and comment.

You might also like

  • Auto responsive dropdown menu

    Auto responsive dropdown menu plugin

    • 815
    • 48
    • 815
    • facebook icon
    • twitter icon
    • google plus
  • Crazy nav highlighter plugin

    Style your menu selection

    • 420
    • 6
    • 420
    • facebook icon
    • twitter icon
    • google plus
  • Select all text on single click

    Text selection has been made easy

    • 269
    • 1
    • 269
    • facebook icon
    • twitter icon
    • google plus

Latest quries posted

gopa kumarabout 4 years ago

amit singhabout 4 years ago

rahmat aliabout 4 years ago

mandavi tiwariabout 4 years ago

rahul sharmaabout 4 years ago

Ask question
Latest video
Learn Angular
Profile pic
Guest Back