HTML5 에서는 sessionStorage라는 session을 클라이언트 쪽에서 쓸 수 있습니다. sessionStorage와 비슷한 저장방법으로는 cookie처럼 다뤄지는 localStorage가 있습니다. 밑에 코드는 html태그입니다.
<p> What is your Mom’s first name? </p>
<form name= "myForm">
<input type= "text" name= "MomName" />
<input type= "submit" onclick= "OnSubmit()" />
<input type= "button" id= "sendbttn" value= "Recall" onclick= "show_alert()" />
</form>
자바스크립트를 이용해 sessionStorage에 값을 저장하고 불러와 쓸 수 있습니다.
sessionStorage는 브라우저가 꺼지면 자동적으로 삭제됩니다.
<script>
//This function is triggered when the user clicks the Submit button
function OnSubmit() {
var mom = document.myForm.MomName.value; //captures the name the user enters
sessionStorage.firstname = mom; //passes the value to the session storage object
}
//This function is triggered when the user clicks the Recall button
function show_alert() {
alert(sessionStorage.firstname); //returns the value stored in the session storage
}
</script>
'Programming > HTML5' 카테고리의 다른 글
[HTML5] Geolocation 현재 위치 표시 (0) | 2013.05.24 |
---|---|
[HTML5] localStorage 사용방법 (0) | 2013.05.24 |