2

Does anyone knows why IE does not accept a string-variable as a parameter to the method setItem? Works fine on Chrome.

Example on IE:

This works:

var itemName = 'anyname';
localStorage.setItem(itemName, 'anything');

This doesn´t:

var itemName = 'anyname';
var stringName = 'some string content';
localStorage.setItem(itemName, stringName );

This gives 'Invalid argument error'.

Any help on that? Thanks! :)

EDIT. That post relates about another problem, the example given in that post(the one that does not work for him) actually works for me! My problem shows that the method setItem does not accept a string variable but accepts a normal enclosed quoted string. Also the solution given in the related post is not acceptable to my problem, I can´t expect that the end user will install a IE11 bug-fix.

Art
  • 237
  • 4
  • 19
  • 1
    related I guess http://stackoverflow.com/questions/21155137/javascript-localstorage-object-broken-in-ie11-on-windows-7 – cvsguimaraes Jul 15 '15 at 16:10

1 Answers1

6

After heavy search, the problem lie in the contents of your string. IE11 setItem method does not accept certain chars. My original string´s contents had things like '|' and '~'.

The only workaround I find is to use the encodeURI(yourStringHere) before sending it to the setItem method and after decodeURI it.

Art
  • 237
  • 4
  • 19