1
I have an input form where I get the link of an image and then a button where it has a function that stores the URL in a variable so that I can dynamically change the image being shown in the img tag in my HTML, my problem is in the fact that, when I insert the image I get the following error:
logo.png%22):1 GET http://localhost/download/url(%22https://s2.logaster.com/Static/v3/img/products/logo.png%22) 403 (Forbidden)
However, when running a console.log at the value passed in the url, I can see that the URL was passed correctly.
Here’s the way I was trying
function changeImage() {
var url = document.getElementById("newImage").value;
document.getElementById('header2-1').src = 'url("' + url + '")';
var log = document.getElementById.src = 'url("' + url + '")';
console.log(log);
}
#header2-1 {
height: 100%;
width: 100%;
background: no-repeat;
}
<span class="navbar-logo">
<a href="https://mobirise.com">
<img id="header2-1" src="https://pt.freelogodesign.org/Content/img/logo-ex-2.png" alt="Mobirise" title="" style="width: 122px; height:98px;">
</a>
</span>
<input type="text" id="newImage">
<input type="button" value="Salvar Imagem" onclick="changeImage();">
Even when I try to access an image that is in the same directory, not from the web, I get the same error.
thanks effort to explain in detail, it is correct its explanation and I could succeed in the task, really the problem was the URL in the string, but I also took the opportunity to correct the other errors of writing
– xnok