How to display image selected on input?

Im trying to display the image selected, but I keep getting the following error:

Not allowed to load local resource:

Any ideas why?

<input type='file' id='fileName' name='fileName' capture='user' accept='image/*'  onchange="document.getElementById('myImg').src = window.URL.createObjectURL(this.files[0])">

<p><img src='#' id='myImg'></p>