0
Well what I was trying to do, was the home page could load a file from the computer itself, and change the image on the index, however I realized that js does not find the image of the index, and when I will try to assign an error occurs, I wanted to know how js, can see all page attributes
My index
<!DOCTYPE html>
<html>
<head>
<title>Exemplo 01</title>
<meta charset="utf-8">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
</head>
<body>
<img src="download.jpg" id="imagem">
<script type="text/javascript" src="js/app.js">
</script>
</body>
</html>
Home
<!DOCTYPE html>
<html>
<head>
<title>Exemplo 01</title>
<meta charset="utf-8">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
</head>
<body>
<div class="container">
<input type="file" id="arquivo">
<br><button onclick="muda()">Mudar imagem</button>
</div>
<script type="text/javascript" src="js/app.js"></script>
</body>
</html>
My js
function muda(){
let imagem = document.getElementById('imagem');
let arquivo = document.getElementById('arquivo');
imagem.src = arquivo.value;
}
It turns out that the file
app.js
is recharged when you give a refresh or changes page to another*, one way to persist the value is by using the Localstorage. You should also use the propertiesfiles
to access the file. By accessingelemento_file.value
, the result, by security measure, will be thefake path
. https://answall.com/a/269912/99718– Valdeir Psr