Below is the HTML snippet:
<textarea cols="5" disabled id="textareRSAKeypair">
@Model["keypair"]
</textarea>
<a href="#" class="btn btn-primary" id="downloadKeypair">Download Key</a>
Here is the jQuery code:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>
$("a#downloadKeypair").click(function () {
var now = new Date().toString();
var filename = 'RSAKeyPair_' + now + ".txt";
$("a#downloadKeypair").attr('Download', filename);
this.href = "data:text/plain;charset=UTF-8," + encodeURIComponent($('#textareRSAKeypair').text());
});
</script>
Despite my efforts, the jQuery code doesn't seem to work on the page. Surprisingly, when I manually paste it into the console (Google Chrome), it functions correctly. I have tried incorporating the document.load
method without success.