Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I've set up a <a href="http://jsfiddle.net/nbp6J/6/" rel="noreferrer">test case</a>, and ran the test in various browsers. The results are below (the inclusive ranges of character codes are mentioned). Tests started at the minimum browser version which support <code>localStorage</code>.</p> <ul> <li>Chrome 5 - 20: <code>0x0000</code> - <code>0xFFFF</code></li> <li>Opera 10.50 - 12.00: <code>0x0000</code> - <code>0xFFFF</code></li> <li>Safari 4.0 - 5.1.7: <code>0x0000</code> - <code>0xFFFF</code></li> <li>Firefox 3.5 - 16<sup>alpha</sup>: <code>0x0000</code> - <code>0xD7FF</code> and <code>0xE000</code> - <code>0xFFFE</code> (0xD800-0xDFFF and 0xFFFF are turned in two characters after LS)</li> <li>IE8, IE9, IE10<sup>PP6</sup>: <code>0x0009</code>, <code>0x000A</code>, <code>0x000D</code>, <code>0x0020</code> - <code>0xD7FF</code> and <code>0xE000</code> - <code>0xFFFD</code>. (Other ranges are either ignored or cause an "Invalid argument" error).<br> <code>0x0000</code> is a NULL-byte, which truncates all following characters in IE.</li> </ul> <p><strong>So, the character ranges <code>0x20</code> - <code>0xD7FF</code> and <code>0xE000</code> - <code>0xFFFD</code> plus <code>0x09</code>, <code>0x0A</code> and <code>0x0D</code> are safe.</strong></p> <hr> <p>I've created three test cases:</p> <ol> <li>The quickest test case, which creates a string with all characters, and tests the value after setting <code>localStorage</code></li> <li>A method which used the SPACE character (0x20) as a delimiter, to properly deal with browsers which create a character with length 2.</li> <li>The worst method, because IE throws an error for invalid strings. Each character is tested individually, which is quite expensive.</li> </ol> <p>All test functions are available in <a href="http://jsfiddle.net/nbp6J/6/" rel="noreferrer">JSFiddle</a>, the first test case is visible below:</p> <pre><code>function run_test(lowerlimit, UPPERLIMIT) {     try {         if (!window.localStorage) {             // I recall that in one of the older Chrome version (4),             // localStorage === null             return 'Localstorage is not supported';         }         if (isNaN(lowerlimit) || isNaN(UPPERLIMIT) || lowerlimit &gt; UPPERLIMIT) {             return 'One of the limits is not a valid number!';         }         var i = lowerlimit - 1;         var character_range = [];         while (++i &lt; UPPERLIMIT) character_range.push(i);         input = String.fromCharCode.apply(String, character_range);         localStorage.setItem('chartest', input);         output = localStorage.getItem('chartest');         if (input === output) {             return true;         }         // Uh oh, not equal!         var result = [];         for (i=0; i&lt;UPPERLIMIT-lowerlimit; i++) {             if (input[i] !== output[i]) {                 result.push(i + lowerlimit);             }         }         return result;     }catch(e){return 'Error:' + e;} } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload