Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6868189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:24:12+00:00 2026-05-27T03:24:12+00:00

I need to verify that Web Storage API is supported and available (it may

  • 0

I need to verify that Web Storage API is supported and available (it may be disabled due to security issues).

So, I thought it would suffice to check whether the type sessionStorage or localStorage is defined or not:

if (typeof sessionStorage != 'undefined')
{
    alert('sessionStorage available');
}
else
{
    alert('sessionStorage not available');
}

However, I was wondering if it could be possible that the type exists, but I wouldn’t been able to use the Web Storage API anyway.

Remarks:
I know Firefox will throw a security error if cookies are disabled and sessionStorage or localStorage are accessed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T03:24:13+00:00Added an answer on May 27, 2026 at 3:24 am

    So, because Modernizr.localstorage respectively Modernizr.sessionstorage will return true while Firefox might be used with disabled Cookies (which will lead into an security error) or any other proprietary (unexpected) behavior could occur: I’ve written my own webStorageEnabled function which seems to work very well.

    function cookiesEnabled()
    {
        // generate a cookie to probe cookie access
        document.cookie = '__cookieprobe=0;path=/';
        return document.cookie.indexOf('__cookieprobe') != -1;
    }
    
    function webStorageEnabled()
    {
        if (typeof webStorageEnabled.value == 'undefined')
        {
            try
            {
                localStorage.setItem('__webstorageprobe', '');
                localStorage.removeItem('__webstorageprobe');
                webStorageEnabled.value = true;
            }
            catch (e) {
                webStorageEnabled.value = false;
            }
        }
    
        return webStorageEnabled.value;
    }
    
    
    // conditional
    
    var storage = new function()
    {
        if (webStorageEnabled())
        {
            return {
                local:   localStorage,
                session: sessionStorage
            };
        }
        else
        {
            return {
                local: cookiesEnabled() ? function()
                {
                    // use cookies here
                }() : null,
    
                session: function()
                {
                    var data = {};
    
                    return {
                        clear: function () {
                            data = {};
                        },
    
                        getItem: function(key) {
                            return data[key] || null;
                        },
    
                        key: function(i)
                        {
                            var index = 0;
                            for (var value in data)
                            {
                                if (index == i)
                                    return value;
                                ++index;
                            }
                        },
    
                        removeItem: function(key) {
                            delete data[key];
                        },
    
                        setItem: function(key, value) {
                            data[key] = value + '';
                        }
                    };
                }()
            };
        }
    }
    

    Hope this will be useful for someone too.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some easy API to verify that a PE file is valid &
I need to verify that a simplified DTD is really a subset of a
I have a type and an interface and I need to verify that the
Say, I have a string that I need to verify the correct format of;
I'm using browser automation for testing web sites but I need to verify HTTP
I'm using browser automation for testing web sites but I need to verify HTTP
Need to verify that the attribute can be applied only to a class that
I have a need to verify a specific hyperlink exists on a given web
I'm in the unfortunate situation where I need to consume web services that do
Error Details: The Web application at http://dev001aaamaaind:333/ could not be found. Verify that you

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.