2
I have a button that when clicked on it, the localStorage takes his ID, then plays the id to the other page, but when I click on the button it is not directing to the other page, only changing the url to the name of the page that is more "boot=1".
HTML:
<input id="inicio" type="date">
<input id="fim" type="date">
<button onclick="postData();">gerar</button>
<div id="dados">
JAVASCRIPT:
function postData() {
var inicio, fim;
inicio = document.getElementById('inicio').value;
fim = document.getElementById('fim').value;
// Default options are marked with *
fetch('http://api_aqui', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: `inicio=${inicio}&fim=${fim}`
}).then(response => response.json().then(data => ({
data: data,
status: response.status
})
).then(res => {
res.data.map(element => {
console.log(element.PRODUTO)
console.log(element.ID)
$('#dados').append(`
<h3>${element.PRODUTO}</h3>
<br>
<form id="form">
<button onClick="pegar(this);" name="botao" value="${element.ID}" href="pagina.php">pegar</button>
<form>
`)
})
})
)
}
function pegar(botao) {
window.localStorage.setItem('produto', `${botao.value}`)
}
Have you tried
window.location.href = 'nomedapagina'
? That question can help you?– bio
Already tried and will not, maybe it is because when I click on the button he plays the parameter to the url of the page that is, then ends up not going to another in the same tab, I had to use the
window.open('nomedapagina'
– Maria