-2
Hello! I have on my index:
<div class="panel-body">
<div id="teste"></div>
</div>
and have in a JS file the following:
function downloadDiv(filename, elementId, mimeType) {
if ($('#teste').html() == "") {
swal("Erro!", "Teste está vazio.", "error");
} else {
var elementHtml = '<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"><style>.checker-hr {padding: 0px;margin: 0px;}</style>\n\n' + document.getElementById('#teste');
var link = document.createElement('a');
//mimeType = mimeType || 'text/plain';
// nome do arquivo que vai ser baixado
var fileName = 'teste.html';
link.setAttribute('download', fileName);
link.setAttribute('href', 'charset=utf-8,' + encodeURIComponent(elementHtml));
link.click();
swal("Sucesso!", "Foi feito o download de teste com sucesso!", "success");
}
}
My idea is to download everything inside the div "test", but this does not work. Does anyone know what I might have done wrong and how to fix it?
I don’t understand what you want to do. Your
<div>
is empty and the code seems to be an attempt to force the user to make an unintended download.– Augusto Vasques
It was just an example. They will have items in the div, but they will always be different items, so I need to put to download, but always give this when I download: https://prnt.sc/r2ibfw
– Ruan
Put a [MCVE], because no one will be kicking whether or not you hit what you do. It doesn’t matter if you’re trying to make a DDA(driven download Attack) only the code has to reflect what you’re asking.
– Augusto Vasques
By a JS code with Jquery I send information into that Div
– Ruan