Skip to content

Instantly share code, notes, and snippets.

@Redolance
Last active June 14, 2018 00:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Redolance/72a14ed66d35a137bd387b00efe37191 to your computer and use it in GitHub Desktop.
Save Redolance/72a14ed66d35a137bd387b00efe37191 to your computer and use it in GitHub Desktop.
preview image on browser before ubload js
<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>
@Redolance
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment