From 8ad7cb3f4b046ea17d1ddff0f84f8c54aad3adee Mon Sep 17 00:00:00 2001 From: Jonathan Frederic Date: Wed, 31 Dec 2014 12:42:17 -0800 Subject: [PATCH] Associate persistence with URL --- IPython/html/static/widgets/js/manager.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/IPython/html/static/widgets/js/manager.js b/IPython/html/static/widgets/js/manager.js index 8ea62457b..1b982daf3 100644 --- a/IPython/html/static/widgets/js/manager.js +++ b/IPython/html/static/widgets/js/manager.js @@ -103,10 +103,20 @@ define([ }; // Use local storage to persist widgets across page refresh by default. + // LocalStorage is per domain, so we need to explicitly set the URL + // that the widgets are associated with so they don't show on other + // pages hosted by the noteboook server. + var url = [window.location.protocol, '//', window.location.host, window.location.pathname].join(''); WidgetManager.set_state_callbacks(function() { - return JSON.parse(localStorage.widgets || '{}'); + if (localStorage.widgets && localStorage.widgets[url]) { + return JSON.parse(localStorage.widgets[url]); + } + return {}; }, function(state) { - localStorage.widgets = JSON.stringify(state); + if (localStorage.widgets === undefined) { + localStorage.widgets = {}; + } + localStorage.widgets[url] = JSON.stringify(state); }); //--------------------------------------------------------------------