Last active
June 14, 2018 00:16
-
-
Save Redolance/72a14ed66d35a137bd387b00efe37191 to your computer and use it in GitHub Desktop.
preview image on browser before ubload js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<form id="form1" runat="server"> | |
<input type='file' id="imgInp" /> | |
<img id="blah" src="#" alt="your image" /> | |
</form> | |
</html> | |
<script> | |
function readURL(input) { | |
if (input.files && input.files[0]) { | |
var reader = new FileReader(); | |
reader.onload = function(e) { | |
document.getElementById('blah').src=e.target.result; | |
} | |
reader.readAsDataURL(input.files[0]); | |
} | |
} | |
document.getElementById('imgInp').addEventListener("change", myFunction); | |
function myFunction() { | |
readURL(this); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For source and other methods on that go here :
https://stackoverflow.com/questions/4459379/preview-an-image-before-it-is-uploaded?answertab=active#tab-top