Im trying to get from urlData the url to use on my fetch. But im getting an error, my fetch is getting the local and input url
function analyzeWebSite() {
const urlData = document.getElementById('url_data');
const url = urlData.value;
if (url === '') {
alert('You need to send a valid website.');
return;
}
fetch(url).then(function (response) {
console.log(response); // show all response from the sended webpage
return response.text().then(function (text) {
console.log(text); // show all the text from the sended webpage
});
});
}
The console error says 404 not found. I think you need to make sure the user adds https or http in the input.
Alternatively, you can modify the user's input:
if(!url.match(/https?:\/\//)){
url = "https://" + url;
}