e.keycode of Printable Characters

Printable Characters keycode

$("#keypresser").keydown(function(e){
var keycode = e.keyCode;

// number keys
var valid =  (keycode > 47 && keycode < 58) || 
// spacebar & return key(s) (if you want to allow carriage returns)
keycode == 32 || keycode == 13 || 
// letter keys
(keycode > 64 && keycode < 91) || 
// numpad keys
(keycode > 95 && keycode < 112) || 
// ;=,-./` (in order)
(keycode > 185 && keycode < 193) || 
// [\]' (in order)
(keycode > 218 && keycode < 223); 
return valid;
});

JS FIDDLE

Advertisements

Save a File in html/txt format.

HTML

<div id="main">
<span>Hey there</span>
</div>
<a id="downloadLink" href="#">Download the inner html</a>

JS

function downloadInnerHtml(filename, elId, mimeType) {
var elHtml = document.getElementById(elId).innerHTML;
var link = document.getElementById("downloadLink");
mimeType = mimeType || 'text/plain';

link.setAttribute('download', filename);
link.setAttribute('href', 'data:' + mimeType + ';charset=utf-8,' + encodeURIComponent(elHtml));
link.click();
}

var fileName = 'tags.pdf'; // You can use the .txt extension if you want
$('#downloadLink').click(function(){
downloadInnerHtml(fileName, 'main','text/pdf');
});

JSFiddle Link