I'm trying to do something like this:
$('button').on('click', function() {
obj = {};
$('pseudoform').find('input,textarea').each(function() {
obj[$(this).attr('name')] = String($(this).val());
});
json = JSON.stringify(obj);
$('input[name=proof]').val(json);
alert('Queria que baixasse: ' + json);
});
textarea,
input,
button {
display: block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><pseudoform><label>Titulo:<inputtype="text" name="title" value="um valor">
</label>
<label>Descrição:
<textarea name="desc">qualquer</textarea>
</label>
<input type="hidden" value="123456" name="challenge">
<input type="hidden" value="999999" name="nonce">
</pseudoform>
<form target="#">
<input type="hidden" value="{valor aqui}" name="proof">
<button>Baixar</button>
</form>
The idea is that value
of proof
is dynamically defined with a json. This json would have the values of all the inputs that exist on top of it, within pseudoform
.
The other step would be for the user to download the content by clicking the "download" button, this is the issue .
How can I make Javascript in the browser force the user to download this content ( {"title":"um valor","desc":"qualquer","challenge":"123456","nonce":"999999"}
) when they click "download"?
The reason for the user to download what he writes is that I need the user to sign the content using OpenGPG, with some smartcard. The server should only receive the json information (which is in the input) and the signature ( armored detached signature file ) of this json.