code: function setupBeforeUnloadListener () {
  		window.addEventListener('beforeunload', function(e) {
  			// Don't save anything unless the user opted in to storage
  			if (!document.cookie.match(/store=(?:prefsAndContent|prefsOnly)/)) {
  				return;
  			}
  			var key;
  			setSVGContentStorage(svgCanvas.getSvgString());
  
  			svgEditor.showSaveWarning = false;
  
  			var curConfig = svgEditor.curConfig;
  			for (key in curConfig) {
  				if (curConfig.hasOwnProperty(key)) { // It's our own config, so we don't need to iterate up the prototype chain
  					var d,
  						storage = svgEditor.storage,
  						val = curConfig[key],
  						store = (val != undefined);
  					key = 'svg-edit-' + key;
  					
  					if (!store) {
  						continue;
  					}
  					if (storage) {
  						storage.setItem(key, val);
  					}
  					else if (window.widget) {
  						widget.setPreferenceForKey(val, key);
  					}
  					else {
  						d = new Date();
  						d.setTime(d.getTime() + 31536000000);
  						val = encodeURIComponent(val);
  						document.cookie = key + '=' + val + '; expires=' + d.toUTCString();
  					}
  				}
  			}
  		}, false);
  	}
docs: emptyLocalStorage(); 
  Listen for unloading: If and only if opted in by the user, set the content
  document and preferences into storage:
  1. Prevent save warnings (since we're automatically saving unsaved
  content into storage)
  2. Use localStorage to set SVG contents (potentially too large to allow in cookies)
  3. Use localStorage (where available) or cookies to set preferences.