From 7c8fafa9ee73ba8182bf874d6412b3c9218ab50c Mon Sep 17 00:00:00 2001 From: Alexis Deveria Date: Wed, 11 Nov 2009 21:13:16 +0000 Subject: [PATCH] Added fix to prevent some FF versions from throwing errors on localStorage check git-svn-id: http://svg-edit.googlecode.com/svn/branches/transformlist@931 eee81c28-f429-11dd-99c0-75d572ba1ddd --- editor/svg-editor.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/editor/svg-editor.js b/editor/svg-editor.js index 47a458a6..91995499 100644 --- a/editor/svg-editor.js +++ b/editor/svg-editor.js @@ -35,12 +35,22 @@ function svg_edit_setup() { var host = location.hostname; var onweb = host && host.indexOf('.') != -1; var store = (val != undefined); - if(window.localStorage && onweb) { - if(store) localStorage.setItem(key, val); - else return localStorage.getItem(key); - } else if(window.globalStorage && onweb) { - if(store) globalStorage[host].setItem(key, val); - else return globalStorage[host].getItem(key); + var storage = false; + // Some FF versions throw security errors here + try { + if(window.localStorage && onweb) { + storage = localStorage; + } + } catch(e) {} + try { + if(window.globalStorage && onweb) { + storage = globalStorage[host]; + } + } catch(e) {} + + if(storage) { + if(store) storage.setItem(key, val); + else return storage.getItem(key); } else if(window.widget) { if(store) widget.setPreferenceForKey(val, key); else return widget.preferenceForKey(key);