Before the preface, the test raised a bug, in the Apple phone in the no-trace mode, the search button is not working, unable to jump page, and search history is not displayed (user search history using Localstorage storage). Text iOS on Sarfari in the non-trace mode, the browser pretends to support Localstorage, and on the global window burst the method, so the checksum is Localstorage object, but when the call SetItem to save, the reportError:quotaexceedederror ...: The quota has been exceeded.As a result, a small test was carried out ... and may not be fully tested! 1. Test model IPhone7 plus version 11.3 iPhone6 plus version 11.3.1 iPhone6 version 10.2.1 Iphonese version 9 Oppe r92. Test browser Sarfa Ri UC comes with browser 3. Results:
IOS9,IOS10 SarfariSetItem error GetItem NULL
IOS SarfariSetItem can be set GetItem can get
IOS to UCSetItem not set, but no error getItem null
AndroCan be set, can get 4. Conclusion: Only IOS9, 10 and localstorage can not be used, IOS11 Sarfari has supported access Localstorage, but iOS11 is not supported in UC. Therefore, the use of loaclstorage in the development process needs to be compatible with the above situation, to avoid JS error after affecting the entire page function. 5. Solve the code and points of attention: 1. Use Try/catch 2. Only for SetItem, to determine whether the browser turns on no trace mode
Determine if browsing supports localstoragefunction islocalstoragesupport{ try { var issupport = ' localstorage ' in Window & & window[' localstorage ']!== null; if (issupport) { Localstorage.setitem ("Local_storage_test", "1"); Localstorage.removeitem ("Local_storage_test"); } return issupport; } catch (e) { return false; }} Determines whether the browser turns on the non-marking mode function isinprivate () { try { localstorage.setitem ("Local_storage_test", "1"); Localstorage.removeitem ("Local_storage_test"); return false; } catch (e) { return true; } }
Localstorage support in Safari non-mark browsing mode in iOS