var output = "";
for(var key in localStorage) {
output += key+"\n";
output += localStorage[key]+"\n";
output += "\n";
}
// output contains combined string
メール部分はこんな感じでやってみてはいかがでしょうかmailto:
、
<a href='mailto:user@domain?subject=[subject here]&body=[email body here]'></a>
これは、次のような関数に組み合わせることができます。
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)
}
使用法:
<a href='javascript:sendLocalStorageByEmail(prompt("Please enter your e-mail address"))'>
Send Email
</a>