9
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

sessionStorageを扱う

Last updated at Posted at 2018-06-05

#Sessionのテンプレート

//セッションへの格納
window.sessionStorage.setItem(['Key'],['Body']);

//セッションの個数の取得
window.sessionStorage.length

//セッションのBodyの取得
window.sessionStorage.getItem(['key']);

//指定したセッションの削除
window.sessionStorage.removeItem(['key']);

//全てのセッションの削除
window.sessionStorage.clear();

#例

window.sessionStorage.setItem(['unique'],['UniqUniq']);
window.sessionStorage.setItem(['personality'],['PersPers']);

var test_size = window.sessionStorage.length
console.log(test_size); 
//結果 => 2

var test = window.sessionStorage.getItem(['unique']);
console.log(test);
//結果 => UniqUniq

window.sessionStorage.removeItem(['unique']);
var test = window.sessionStorage.getItem(['unique']);
console.log(test);
//結果 => nil

window.sessionStorage.clear();
var test1 = window.sessionStorage.getItem(['unique']);
var test2 = window.sessionStorage.getItem(['personality']);
console.log(test1);
console.log(test2);
//結果=> nil
//           nil
9
7
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?