var output = "";
for(var key in localStorage) {
output += key+"\n";
output += localStorage[key]+"\n";
output += "\n";
}
// output contains combined string
As for the email part you could try using a mailto:
like this,
<a href='mailto:user@domain?subject=[subject here]&body=[email body here]'></a>
This could be combined into a function like this:
function sendLocalStorageByEmail(recipient) {
// create localstorage string
var output = "";
for(var key in localStorage) {
output += key+"\n";
output += localStorage[key]+"\n";
output += "\n";
}
// create temporary anchor to emulate mailto click in new tab
var anchor = document.createElement("a");
anchor.href = "mailto:"+recipient+"?subject=Local+Storage+Data&body="+encodeURIComponent(output);
anchor.style.display = "none";
anchor.setAttribute("target","_blank");
anchor.appendChild(document.createTextNode(""));
document.body.appendChild(anchor);
if (anchor.click) {
return anchor.click();
}
// some browsers (chromium/linux) have trouble with anchor.click
var clickEv = document.createEvent("HTMLEvents");
clickEv.initEvent("click", true, true);
anchor.dispatchEvent(clickEv)
}
Usage:
<a href='javascript:sendLocalStorageByEmail(prompt("Please enter your e-mail address"))'>
Send Email
</a>