10 examples of 'sessionstorage in javascript' in JavaScript

Every line of 'sessionstorage in 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}
8setItem(key, value) {
9 $window.sessionStorage.setItem(this._getStorageKey(key), value)
10}
86public saveInLocalStorage() {
87 let session: SESSION = this;
88 window.localStorage.setItem(SESSION.const.SESSION_LOCAL_STORAGE, JSON.stringify(session));
89}
15setItem (key, value) {
16 if (value instanceof Object) {
17 sessionStorage.setItem(
18 key,
19 JSON.stringify(value)
20 )
21 } else {
22 sessionStorage.setItem(value)
23 }
24}
27public setObject(key: string, value: any): void {
28 this.sessionStorage[key] = JSON.stringify(value);
29}
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}
14export function getSessionStorage() {
15 return (typeof window !== 'undefined') ? window.sessionStorage : null;
16}
63function SetSessionCookie(cookieName, cookieValue, path, domain) {
64 document.cookie = cookieName+"="+escape(cookieValue) + ";path="+path+";domain="+domain;
65}
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}

Related snippets