最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Disable local storage but not cookies in Firefox - Stack Overflow

programmeradmin2浏览0评论

I would like to create a webpage that will use local storage if it is available, but if not (e.g. the user's browser doesn't support it), will attempt to use cookies instead. In order to test this functionality on my own puter, which has only modern browsers installed, I'd like to simulate an older browser by disabling local storage while leaving cookies allowed. In Firefox, the dom.storage.enabled option apparently cannot do this, because it affects both local storage AND cookies. Any way around this?

I would like to create a webpage that will use local storage if it is available, but if not (e.g. the user's browser doesn't support it), will attempt to use cookies instead. In order to test this functionality on my own puter, which has only modern browsers installed, I'd like to simulate an older browser by disabling local storage while leaving cookies allowed. In Firefox, the dom.storage.enabled option apparently cannot do this, because it affects both local storage AND cookies. Any way around this?

Share Improve this question asked Oct 10, 2013 at 14:27 baixiweibaixiwei 1,0294 gold badges20 silver badges27 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

Presumably you have something like if(window.localStorage) to test the feature. Dummy it out.

// nuke it pletely:
if( window.localStorage && false)

// add a "debug mode":
if( window.localStorage && !location.href.match(/[?&]nolocalstorage=1/))
// access your page with example./file.html?nolocalstorage=1

There are other ways, of course, but this should give you the general idea.

As a quick and dirty solution, you could run this script in your browser for temporary disabling:

delete window.localStorage;
发布评论

评论列表(0)

  1. 暂无评论