JavaScript localStorage object broken in IE11 on Windows 7

后端 未结 4 1752
醉话见心
醉话见心 2020-11-27 04:08

The localStorage object in Internet Explorer 11 (Windows 7 build) contains string representations of certain functions instead of native calls as you would expe

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-27 05:12

    It's not just IE11's fault.

    Probably WEINRE is injected into the page. It hooks into several system functions to provide Developer Tools functionality, but IE11 interprets assignments to the localStorage and sessionStorage properties wrong, and converts the hook functions into strings, as if they were the data that is going to be stored.

    There's a comment in the apache/cordova-weinre repo which says:

            #In IE we should not override standard storage functions because IE does it incorrectly - all values that set as
            # storage properties (e.g. localStorage.setItem = function()[...]) are cast to String.
            # That leads to "Function expected" exception when any of overridden function is called.
            object[property] = hookedFunction  unless navigator.userAgent.match(/MSIE/i) and (object is localStorage or object is sessionStorage)
    

    Looks like it's either an old version of WEINRE being used, or this change hasn't been officially released (it's been there since 2013).

提交回复
热议问题