10 examples of 'sessionstorage javascript' in JavaScript

Every line of 'sessionstorage javascript' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
106public getSessionStorage(sessionId: string) {
107 if (this.storages[sessionId]) {
108 return this.storages[sessionId]
109 }
110 const prefix = `${this.endpoint}:${sessionId}:`
111 const store = {
112 clear: () => {
113 Object.keys(localStorage)
114 .filter((key: string) => key.startsWith(prefix))
115 .forEach(key => localStorage.removeItem(key))
116 },
117 getItem: (key: string) => {
118 return localStorage.getItem(prefix + key)
119 },
120 setItem: (key: string, item: string) => {
121 return localStorage.setItem(prefix + key, item)
122 },
123 removeItem: (key: string) => {
124 return localStorage.removeItem(prefix + key)
125 },
126 }
127 this.storages[sessionId] = store
128 return store
129}
145public saveSession(session: Session, save: boolean = false) {
146 this.project.sessions[session.id] = session
147 if (save) {
148 this.saveProject()
149 }
150}
61onGetSession(){ this.value = sessionStorage.getItem( this.key );}
108static getSessionData(key: string): any {
109 const sessionStorage = BrowserStorage.getSessionStorage();
110
111 if(sessionStorage) {
112 try {
113 const item = sessionStorage.getItem(key);
114
115 if(item) {
116 return item ? JSON.parse(item) : null;
117 }
118
119 return null;
120 } catch(error) {
121 return null;
122 }
123 } else {
124 return null;
125 }
126}
131function showSessionStorage(){
132 if (window.sessionStorage) {
133 s_btn_tips.innerHTML = 'sessionStorage:' + JSON.stringify(session_storage);
134 } else {
135 s_btn_tips.innerHTML = '浏览器不支持sessionStorage';
136 }
137}
86public saveInLocalStorage() {
87 let session: SESSION = this;
88 window.localStorage.setItem(SESSION.const.SESSION_LOCAL_STORAGE, JSON.stringify(session));
89}
105public static removeFromLocalStorage() {
106 window.localStorage.removeItem(SESSION.const.SESSION_LOCAL_STORAGE);
107}
14export function getSessionStorage() {
15 return (typeof window !== 'undefined') ? window.sessionStorage : null;
16}
16createSession(sessionId, object) {
17 this.sessions[sessionId] = object;
18}
10export function updateUserSessionStores(): void {
11 if (new Date().toDateString() !== lastDayActive) {
12 daysActiveCount++
13 lastDayActive = new Date().toDateString()
14 localStorage.setItem('days-active-count', daysActiveCount.toString())
15 localStorage.setItem('last-day-active', lastDayActive)
16 }
17}

Related snippets