วันพุธที่ 27 ตุลาคม พ.ศ. 2553

html5 local storage

คุณสมบัติใหม่ของ html5 : local storage ซึ่งจะเก็บข้อมูลไว้ได้นานและมากกว่า cookie หลายเท่า

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>html5</title>
<script type="text/javascript">
function save_data(){
localStorage.setItem('mydata', document.getElementById('t1').value);
}
window.onload = function(){
document.getElementById('t1').value = localStorage.mydata;
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>

ข้อมูลจะยังคงอยู่แม้ว่าจะปิด browser หรือลบ cookie ไปแล้ว<br/>

<textarea id="t1" cols="80" rows="15"></textarea>
<button onclick="save_data();">save</button>

</body>
</html>

ไม่มีความคิดเห็น:

แสดงความคิดเห็น