Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@interduo
Created January 18, 2022 07:50
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 interduo/b27f79a82f636c73793e24f1fe837fda to your computer and use it in GitHub Desktop.
Save interduo/b27f79a82f636c73793e24f1fe837fda to your computer and use it in GitHub Desktop.
#this works only in FF
<html>
<input type="file" >
<object id="view" type="application/pdf" width="100%" height="100%"></object>
</html>
<script type="text/javascript">
var fileInput = document.querySelector('input');
var elem = document.querySelector('object');
fileInput.onchange = () => {
var file = fileInput.files[0];
var objUrl = window.URL.createObjectURL(file);
elem.setAttribute('data', objUrl);
URL.revokeObjectURL(objUrl);
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment