javascript - File upload jquery instead of preview the file it show the link in the below new window -
working on jquery file upload don't want use plugin.using pure jquery / javascript. instead of preview file want link (view) needs display once image & pdf upload if user click link has open in new page.
here html code
any guidance here please
<div class="mob_pass"> <label class="ctm_fnt">attach document</label> <br> <div class="custom-file-input"> <input type="file"> <input type="text" class="txt_field ctm_widt" placeholder="attached file"> <button class="cst_select"> <i class="fa fa-rotate-90"></i> attach </button> </div> </div>
kindly me.
thanks in advance
here fiddle link
add markup :
<a href="#" target="_blank" class="preview">view</a>
in js, capture event of input change, preview , set a
's href
data url get.
hide a
(when no file selected), , show again once have show.
var $preview = $(".preview"); $preview.hide(); $("input").on("change", function(){ var files = this.files; var filereader = new filereader(); filereader.onload = function(e){ $preview.attr("href", e.target.result); $preview.show(); }; filereader.readasdataurl(files[0]); });
Comments
Post a Comment